Results 1 to 3 of 3

Thread: Random numbers [resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113

    Random numbers [resolved]

    Ok then, I need help with VB code to generate six random unique numbers in the range of 1 thru 49 inclusive. I have my array declared and have tried to use the combination of Randomize and Rnd functions, which is working except that it's, at times, generating duplicate numbers......
    Last edited by SmagO; Jun 8th, 2005 at 03:43 AM. Reason: resolved
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Random numbers

    Try this:

    VB Code:
    1. Private Function MakeRandom(intLowest As Integer, intHighest As integer) As Long
    2.     Ramdomize
    3.     Din intTemp As Integer
    4.     If intLowest > intHighest Then
    5.         intTemp = intLowest
    6.         intLowest = intHighest
    7.         intHighest = intTemp
    8.     End If
    9.     MakeRandom = CLng((intHighest - intLowest + 1) * Rnd + intLowest)
    10. End Function

    Or, have a look here for some new functions that were develped for this job

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

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