use session_id() to seed randomizer: effective?
Posted: Wed Jun 29, 2005 4:04 pm
i need to generate some numbers to seed MySQL's rand() function, and the results must be reproducable -- so I need a seed I can access across multiple scripts. right now i'm doing this:
which seems to work fine, just stripping out all the alphas from the session id. it returns numbers around 20 digits long, +/-, and i've found that anything beyond the 19th digit is insignificant in this instance. (ie, for any seed N longer than 19 digits, N and N+1 produce identical results.)
my question is: does anyone know much about the way session ids are generated, and if they're appropriate for this? right now i'm just assuming that any 2 session IDs will be sufficiently varied so as to produce conspicuously different results, but i don't have any proof to that effect. (i only need pseudo-randomization, so i don't care about statistically significant differences, only an apparent shuffle.) and if i'm going to truncate the result i get, would the 1st 19 digits be more significant than the last 19 digits, or vice versa? or does it matter?
also, on a side note: i tried using but i was getting unpredictable errors; i managed to determine that it only happened when i called base_convert from within an output buffer, but i couldn't get it to happen predictably. when it would fail, the whole script would fail silently and i'd get a 302 response from the server, which is odd in itself. any insight into that one? php 4.1.1, apache 1.3.20.
Code: Select all
$seed = preg_replace('/\D/', '', session_id());my question is: does anyone know much about the way session ids are generated, and if they're appropriate for this? right now i'm just assuming that any 2 session IDs will be sufficiently varied so as to produce conspicuously different results, but i don't have any proof to that effect. (i only need pseudo-randomization, so i don't care about statistically significant differences, only an apparent shuffle.) and if i'm going to truncate the result i get, would the 1st 19 digits be more significant than the last 19 digits, or vice versa? or does it matter?
also, on a side note: i tried using
Code: Select all
$seed = base_convert(session_id(), 16, 10);