Re: Random generator
From: Sandman (mr_at_sandman.net)
Date: 04/13/04
- Next message: John Pastrovick: "Re: SQL syntax to update records with diff'rent function generated random PINS"
- Previous message: John Pastrovick: "Re: SQL syntax to update records with diff'rent function generated random PINS"
- In reply to: Garp: "Re: Random generator"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 13 Apr 2004 09:15:02 +0200
In article <6HFec.2251$i67.22112301@news-text.cableinet.net>, "Garp"
<garp7@no7.blueyonder.co.uk> wrote:
>>> I am using the same algorithm, but using Random and as you say, they
>>> generate the random numbers differently, I've not time to now to try
>>> out your answer above, but what does it actually mean?
>>>
>>> They way I understood the VB and PHP randomiser for that matter, is
>>> that if I seed them, I will get a random number each time but its a
>>> psudo random number, in so much as each time I call it the random
>>> numbers are repeatable.
>>
>> How do you know you're using the same pseudo-random algorithm? The
>> rand function in PHP uses the C rand function, which may differ from
>> C library to C library.
>
> Almost certainly.
>
> What the PRNG system does is calculate a seemingly random number based
> on a seed value, using an algorithm like the one I posted above. That
> will produce a predictable sequence from known seeds, but seed it from
> time() and it will be as random as you need.
I suggest using microtime() instead, if you may want to access a random value
more than once in a second.
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
-- Sandman[.net]
- Next message: John Pastrovick: "Re: SQL syntax to update records with diff'rent function generated random PINS"
- Previous message: John Pastrovick: "Re: SQL syntax to update records with diff'rent function generated random PINS"
- In reply to: Garp: "Re: Random generator"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|