Hi all,
I have a few questions about the srand (or mt_) function for directed
seeding.
I'm assuming if I do a targeting seeding with a particular value, I'll
get the same sequence of values no matter how many times I run the page
(assuming it's on the same OS and php version). Of course, if this is
incorrect, please let me know. But I have a few questions.
1) What is the persistence of the random seed?
a) If I run another script on the same server subdomain that does NOT
seed the random number generator, will it re-seed from a "random value"
(as the manual puts it) or will it run off the sequence from the seed
initialized in my targetted script? On another subdomain hosted on the
same computer (same user account, etc)? Does it make a difference if
the page has the same URL (I replace one version of the page with
another that removes the seed line or use the seed function in an
include file used by both scripts)?
b) If I seed in two separate pages with the same seed number and draw 10
random values, I'd expect to get the same sequence if the two scripts
are run sequentially. But what if I seeded one, put in a 20 second
delay (but did not grab any values yet), ran the other script (without
the delay), and then allowed the first script to finish by grabbing 10
values. Would the draw from one page affect the other?
c) If each file/script does not inherit the random seed, locally what is
the heritability? In other words, does the sequence persist outside of
the function in which the random number is seeded? Or does a different
function re-seed itself automatically?
d) Would php's random number generator be influenced by other programs
running on the system (assuming they're not tampering with the memory
allocated to the running script)?
2) What is the cycle period?
a) Is a seeded random value expected to repeat its generated sequence in
fewer than getrandmax for a seeded random number? An unseeded one?
b) Is there built-in cycle detection and auto-reseeding?
c) If I draw the same number (e.g. 12345) as before, would I expect the
next value to be the same as the previous time I saw 12345 (assuming my
range is from 0 to getrandmax)? Or is there a secondary number stored
somewhere which is what the next random number is calculated in
conjunction with?
d) Has anyone ever looked into the distribution of cycle times (if it
does indeed cycle). If so, what's the mean, median, variance/stdev and
is it a near-gaussian distribution?
e) Are any seed values known to be intrinsically poor at avoiding a
cycle? Are there any (known) seed values that bias draws high/low or
even/odd, or can I assume given enough calls I'll get ABOUT half and
half (gaussian-like distribution)?
3) To simulate the basal behavior of the unseeded rand call (but want to
repeat with that same seed value later), do I just get the microtime,
store it somewhere (e.g. mtvar), and then call srand($mtvar)? Or is the
autogenerated "random seed" not based on the current clock or via a hash
of the clock?
If any of these answers are significantly different for mt_srand vs
srand, I'd appreciate knowing about both. However, I'll take whatever
information you do know. So, even if you only know the answer to one
part of one of these questions, I'd still appreciate your response.
--Matt
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php