suggestion for "improving" prng implementation

andrew cooke andrew at acooke.org
Tue Oct 15 22:14:11 CEST 2002

```hi,

i know that this isn't a bug - i understand a little about
multiplicative congruential generators and know that there is not
intended to be any guarantee of independence between sequences from
different seeds (hence the jumpahead functionality etc).

however, random numbers are used in a wide range of applications.
while many require careful thought about the statistical properties,
others only need something that is "fairly random".  so if there's a
simple way to make the implementation of the prng more useful in the
latter group, without harming the former group, then it seems worth

if you look at the output i'll paste below, you'll see that the first
couple of values of sequences with neighbouring seed values are
strongly correlated across sequences (this is understandable, given
the algorithms used).  but if the first few (4?) values after seeding
were automatically generated and dropped, then this correlation would
be unimportant to "fairly random" applications.

a change like this would let a someone writing a game (say) use
seeding to generate "different" sequences without needing to worry
that (say) the first move of the computer controlled alien will be to
the same on successive level, etc etc...

(there is one danger - if people require repeatable sequences from
seeds across python versions.  this change would break that
repeatability).

i just want to repeat again that this is simply to make life easier
for "quick and dirty" uses of the prng.  i am not claiming that this
change will improve the prng for "serious" use.

cheers,
andrew

>>> random.seed(123)
>>> for i in range(10): print random.random(),
...
0.711800244467 0.717910754873 0.78581128287 0.248291539217
0.927000874956 0.767848388239 0.163218671249 0.989680083335
0.492734220966 0.941375396456
>>> random.seed(124)
>>> for i in range(10): print random.random(),
...
0.71744958868 0.683948615391 0.978285431339 0.16137092737
0.0635762491011 0.122237367062 0.763734050019 0.677809853067
0.162924845037 0.543972112568
>>> random.seed(125)
>>> for i in range(10): print random.random(),
...
0.723098932894 0.649986475908 0.170759579808 0.0744503155232
0.200151623246 0.476626345885 0.364249428789 0.365939622798
0.833115469108 0.146568828681
>>> random.seed(126)
>>> for i in range(10): print random.random(),
...
0.728748277107 0.616024336425 0.363233728276 0.987529703676
0.336726997391 0.831015324709 0.96476480756 0.0540693925296
0.503306093179 0.749165544793
>>> random.seed(127)
>>> for i in range(10): print random.random(),
...
0.734397621321 0.582062196943 0.555707876745 0.900609091829
0.473302371537 0.185404303532 0.56528018633 0.742199162261
0.17349671725 0.351762260905
>>> random.seed(128)
>>> for i in range(10): print random.random(),
...
0.740046965534 0.54810005746 0.748182025214 0.813688479982
0.609877745682 0.539793282355 0.165795565101 0.430328931992
0.84368734132 0.954358977017
>>> random.seed(129)
>>> for i in range(10): print random.random(),
...
0.745696309748 0.514137917978 0.940656173683 0.726767868135
0.746453119827 0.894182261178 0.766310943871 0.118458701724
0.513877965391 0.556955693129

```