|
-
May 22nd, 2001, 06:50 PM
#1
Thread Starter
Hyperactive Member
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.
-
May 23rd, 2001, 02:01 AM
#2
Guru
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;
}
-
May 23rd, 2001, 12:03 PM
#3
They are called pseudo-random number generators. This is because the numbers are not truly random. Guv explained this here
-
May 24th, 2001, 05:47 PM
#4
Thread Starter
Hyperactive Member
Ok, I´ll check it.
Thanks.
If things were easy, users might be programmers.
-
May 26th, 2001, 03:54 PM
#5
Addicted Member
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:
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?
-
May 26th, 2001, 04:13 PM
#6
Frenzied Member
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."
-
May 26th, 2001, 04:21 PM
#7
Addicted Member
Originally posted by Lemon Lime
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?
-
May 26th, 2001, 05:09 PM
#8
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.
-
May 27th, 2001, 05:28 AM
#9
Frenzied Member
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."
-
May 30th, 2001, 03:18 PM
#10
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|