Results 1 to 10 of 10

Thread: How are random numbers generated?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2000
    Location
    Mexico City
    Posts
    306

    How are random numbers generated?

    Hi !!!

    How are the random numbers generated???

    I guess that has to be a constant probabilistic distribution, but... How???

    Any clue??
    If things were easy, users might be programmers.

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Here's how they were generated last time I checked:
    (Code simplified for obvious reasons)
    Code:
    long CurrentSeed = 1;
    
    void srand(long Seed)
    {
    	CurrentSeed = Seed;
    }
    
    long rand()
    {
    	CurrentSeed = ((CurrentSeed * 214013 + 2531011) >> 16) & 0x7FFF;
    	return CurrentSeed;
    }

  3. #3
    jim mcnamara
    Guest
    They are called pseudo-random number generators. This is because the numbers are not truly random. Guv explained this here

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2000
    Location
    Mexico City
    Posts
    306
    Ok, I´ll check it.
    Thanks.
    If things were easy, users might be programmers.

  5. #5
    Addicted Member Lemon Lime's Avatar
    Join Date
    Jul 2000
    Location
    Space, the final frontier, go along the yellow brick road,turn left then left again. In the service window, ask for the insane dude.
    Posts
    167
    i think that random procedure is actually generated by the computer timer. the number is the time that has passed in seconds, and semiseconds. the semiseconds are returned from the function as a number between 0 to 1 and they are always generating the same numbers!!!
    it is due to the fact that the CPU speed is not changed. therefore it has to change the timer!
    in basic implementation it goes like:
    Code:
    Randomize Timer
    it is regenerate the numbers, by resetting the time, a bit...
    as the mater of fact, it is ruining the internal timer, if used a lot of time (especially in loops).
    I've had enough with sainity!
    What's the use of it anyway?

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Randomize Timer just seeds the Rnd function with the current value of the timer, it doesn't use the timer more than once.
    Harry.

    "From one thing, know ten thousand things."

  7. #7
    Addicted Member Lemon Lime's Avatar
    Join Date
    Jul 2000
    Location
    Space, the final frontier, go along the yellow brick road,turn left then left again. In the service window, ask for the insane dude.
    Posts
    167
    Originally posted by Lemon Lime

    Code:
    Randomize Timer
    it is regenerate the numbers, by resetting the time, a bit...
    as the mater of fact, it is ruining the internal timer, if used a lot of time (especially in loops).
    what i meant was that in:
    Code:
    Do
    Randomize Timer
    Line -(Rnd*MaxResolutionX, Rnd*MaxResolutionY)
    DoEvents
    Loop
    it'll show different thing than in:
    Code:
    Do
    'Randomize Timer
    Line -(Rnd*MaxResolutionX, Rnd*MaxResolutionY)
    DoEvents
    Loop
    C?
    I've had enough with sainity!
    What's the use of it anyway?

  8. #8
    Zaei
    Guest
    Of course it will. By calling "Randomize Timer", you are setting the seed for the random number generator. By NOT calling it, you ARENT setting the seed, so its using either a default value, or some other value for the Seed. For instance, running this code:
    Code:
    Dim i As Long
    For i = 0 To 25
        Randomize 0
        Text1.Text = Text1.Text & vbCrLf & CStr(Rnd() * 25)
    Next i
    ...will always return the same series of numbers. This is actually the basis for an old game called "Elite". By Seeding the random number generator with a certain number, an entire universe is created by the game. That way, the only thing that actually needed to be saved to regenerate the same exact universe was the seed value.

    Z.

  9. #9
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Is that how it worked? That's a really cool idea I'll have to remember that. You can use the same for randomly generated structures like trees in landscape engines, I've seen that before.

    In actual fact, this code:
    Code:
    Dim i As Long
    For i = 0 To 25
        Randomize 0
        Text1.Text = Text1.Text & vbCrLf & CStr(Rnd() * 25)
    Next i
    would return the same number 26 times wouldn't it?
    Harry.

    "From one thing, know ten thousand things."

  10. #10
    Addicted Member Lemon Lime's Avatar
    Join Date
    Jul 2000
    Location
    Space, the final frontier, go along the yellow brick road,turn left then left again. In the service window, ask for the insane dude.
    Posts
    167
    well, it is!!!
    and it'll work, but the REALLY generated random numbers are with Randomize Timer!
    The main idea of random numbers is that they are REALLY random!
    if u want to have random numbers, u should use the RANDOMIZE TIMER, and the seed should be quite random too!!!

    c?
    I've had enough with sainity!
    What's the use of it anyway?

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