Results 1 to 6 of 6

Thread: Random Numbers

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Toronto, Ontario
    Posts
    2
    When I start my program I want to create random numbers but when I enter the code it will always display the random numbers in the same order, when I exit and re-open the program. How do I make it so that everytime I relaunch the program it generates random numbers in a completely different order?

    Thanks,

    Will

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Are you using the Rnd function?? If so you need to make a call to the Randomize function before hand to assure that you don't always get the same values....

    Code:
    Dim iCt as Integer
    dim iArray(1 to 5) as Integer
    
    For iCt = 1 to 5
    
     Randomize
     iArray(iCt) = rnd * 20
    
    Next iCt
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3
    New Member
    Join Date
    Dec 2000
    Location
    South Florida
    Posts
    1

    Arrow

    I would prolly put the randomize function at the start of your code, you should only need to call it once to "seed" the random number generator.


    Gazz

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    I don't know the difference between
    Code:
    Randomize
    And
    Code:
    Randomize Timer
    Some people use Randomize Timer, I don't know why.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Good point gazz here is the corrected code..

    Code:
    Dim iCt as Integer
    dim iArray(1 to 5) as Integer
    
    Randomize
    
    For iCt = 1 to 5
    
     iArray(iCt) = rnd * 20
    
    Next iCt
    Also there is no point in saying Randomize Timer because according to VB Help file if you omit the seed parameter the Timer is automatically used to generate the random seed


    From the visual basic reference

    Randomize Statement
    Initializes the random-number generator.

    Syntax

    Randomize [number]

    The optional number argument is a Variant or any valid numeric expression.

    Remarks

    Randomize uses number to initialize the Rnd function's random-number generator, giving it a new seed value. If you omit number, the value returned by the system timer is used as the new seed value.

    If Randomize is not used, the Rnd function (with no arguments) uses the same number as a seed the first time it is called, and thereafter uses the last generated number as a seed value.

    Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Toronto, Ontario
    Posts
    2

    Thumbs up Thanks

    Thanks for the help

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