Results 1 to 5 of 5

Thread: Random Numbers

  1. #1

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195

    Random Numbers

    I have 16 labels on a form andd would like to generate 16 randoms numbers,from 1 thru 16.

    The only trick is that they must be unique.

    I can't figure out how to do this and looked pretty much everywhere.

    Any suggestions would be helpful.

    Thanks.

  2. #2
    Lively Member
    Join Date
    Nov 2003
    Location
    Iowa
    Posts
    96
    So you want each one to be differant but in a random order? I suggest just making it so that if the number is already used it would add 1 to the # until it's a unused #...if the # gets to 16 then it would go back to 1...

    Does this help?


    Also make sure you use Randomize() in your Form Load otherwise the numbers will be the same every time you run your program, the Random Function is based on your computers clock, and the first time it's built, is the only time it'll get the #'s unless you add the randomize()
    It is like wiping your ass with silk, I love it!

  3. #3

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Yes,

    Just after posting I found a solution.

    Another trick I'd also like to do is:

    I have 16 labels allow the numbers 1-8 to be used, but only 2 times a piece.

    Any Solution?

  4. #4
    Addicted Member
    Join Date
    Mar 2002
    Location
    St. Louis MO
    Posts
    129
    One way I can think of offhand is to use an array 1 throu 32 to hold your values.
    Array(1)=1
    Array(2)=1
    Array(3)=2
    Array(4)=2
    Array(5)=3
    Array(6)=3
    .
    .
    .
    Array(31)=16
    Array(32)=16

    Next do a for loop from 1 to 32,
    each loop cycle pick a random array index and swap it's value with the array index by your loop counter. This has the net effect of putting your array into a random order..

    Finally, make another loop that assigns lablel captions to array indexes..
    Label(1).capton=Array(1)
    Label(2).capton=Array(2)
    etc..

    If you need a code example let me know.

  5. #5
    Addicted Member
    Join Date
    Mar 2002
    Location
    St. Louis MO
    Posts
    129

    Woops! You said 16...

    Woops! I meant to say Array 16 elements in size and numbers that go up to 8 (not 32)

    Geez I need to switch to decaf.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width