Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    6 Unique Random Numbers (XP; SP3)

    How would one control the random number to only return six unique values?

    The code I have been toying with generates duplicate values:

    Sub RandomNumbers_6_Unique()
    oNo1 = Int((6 * Rnd) +1)
    oNo2 = Int((6 * Rnd) +1)
    oNo3 = Int((6 * Rnd) +1)
    oNo4 = Int((6 * Rnd) +1)
    oNo5 = Int((6 * Rnd) +1)
    oNo6 = Int((6 * Rnd) +1)

    MsgBox oNo1 & "-" & oNo2 & "-" & oNo3 & "-" & oNo4 & "-" & oNo5 & "-" & oNo6

    End Sub


    This is a test to return only numbers between 1 and 6. Eventually I will expand it and only want 6 unique random numbers returned.

    Thanks,
    John

  2. #2
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Doorn, Netherlands
    Posts
    311
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 6 Unique Random Numbers (XP; SP3)

    Get yourself the freeware morefunc(tions) addin from

    http://longre.free.fr

    Regards,
    Teunis

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 6 Unique Random Numbers (XP; SP3)

    I think you will have to use VBA to do this. Does this <post#=222,852>post 222,852</post: > give you enough to do what you want?
    Legare Coleman

  4. #4
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Doorn, Netherlands
    Posts
    311
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 6 Unique Random Numbers (XP; SP3)

    Link made clickable by HansV

    Sorry,

    The morefunc site was updated to

    http://xcell05.free.fr/

    Regards,
    Teunis

Posting Permissions

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