Hi !!!
How are the random numbers generated???
I guess that has to be a constant probabilistic distribution, but... How???
Any clue??
Printable View
Hi !!!
How are the random numbers generated???
I guess that has to be a constant probabilistic distribution, but... How???
Any clue??
Here's how they were generated last time I checked:
(Code simplified for obvious reasons) :rolleyes:
Code:long CurrentSeed = 1;
void srand(long Seed)
{
CurrentSeed = Seed;
}
long rand()
{
CurrentSeed = ((CurrentSeed * 214013 + 2531011) >> 16) & 0x7FFF;
return CurrentSeed;
}
They are called pseudo-random number generators. This is because the numbers are not truly random. Guv explained this here
Ok, I´ll check it.
Thanks.
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...Code:Randomize Timer
as the mater of fact, it is ruining the internal timer, if used a lot of time (especially in loops).
Randomize Timer just seeds the Rnd function with the current value of the timer, it doesn't use the timer more than once.
what i meant was that in:Quote:
Originally posted by Lemon Lime
it is regenerate the numbers, by resetting the time, a bit...Code:Randomize Timer
as the mater of fact, it is ruining the internal timer, if used a lot of time (especially in loops).
it'll show different thing than in:Code:Do
Randomize Timer
Line -(Rnd*MaxResolutionX, Rnd*MaxResolutionY)
DoEvents
Loop
C?Code:Do
'Randomize Timer
Line -(Rnd*MaxResolutionX, Rnd*MaxResolutionY)
DoEvents
Loop
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:
...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.Code:Dim i As Long
For i = 0 To 25
Randomize 0
Text1.Text = Text1.Text & vbCrLf & CStr(Rnd() * 25)
Next i
Z.
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:would return the same number 26 times wouldn't it?Code:Dim i As Long
For i = 0 To 25
Randomize 0
Text1.Text = Text1.Text & vbCrLf & CStr(Rnd() * 25)
Next i
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?