to generate four random numbers

Can anyone tell me how to generate four random numbers at one time, but can not repeat the digits. For example 1234 is allowed, but 1223 is not allowed.
Thank You

Comments

  • : Can anyone tell me how to generate four random numbers at one time, but can not repeat the digits. For example 1234 is allowed, but 1223 is not allowed.
    : Thank You
    :
    Try this:

    [code]

    Dim intNumsGenerate As Integer, intGeneratedNum As Integer
    Dim intLastNum As Integer, intCount As Integer

    'Randomize() is used to initialise Rnd() function
    Randomize
    'Generate 4 numbers
    intNumsGenerate = 4

    For intCount = 0 To intNumsGenerate - 1
    'Store the generated number to check with the next one
    intLastNum = intGeneratedNum
    Do
    'Rnd() generates a number between 0 and 1
    intGeneratedNum = 10 * Rnd()
    'Make sure the number generated is not same as the last and
    'number generated by Rnd() is not 1 as that will give us a
    'generated number of 10
    Loop Until (intGeneratedNum <> intLastNum And intGeneratedNum < 10)
    'Display in a textbox called txtGenerate
    txtGenerate.Text = txtGenerate.Text + Trim(Str(intGeneratedNum))
    Next intCount
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion