Issue1817

classification
Title: Small random seeds do not produce random values (as in CPython)
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: fdb, fwierzbicki, santa4nt, zyasoft
Priority: normal Keywords:

Created on 2011-11-16.15:01:18 by fdb, last changed 2014-05-22.00:01:27 by zyasoft.

Files
File name Uploaded Description Edit Remove
random-seed.py fdb, 2011-11-16.15:05:53 Random seed example file.
Messages
msg6721 (view) Author: Frederik De Bleser (fdb) Date: 2011-11-16.15:05:53
Take the following code:

from random import seed, choice
for i in range(1000):
  seed(i)
  print choice("abcdef"),


In Jython 2.5.2, this produces only letter "e"'s, 1000 after each other.
In Python 2.7.1, this produces a random variation for every seed.

In Jython, higher seeds do work, so using 

  seed(math.pow(i, 5))

would generate "better" random variations.
msg7962 (view) Author: Santoso Wijaya (santa4nt) Date: 2013-03-22.23:57:52
That sounds like an abuse of an PRNG. AFAIK, a PRNG is only supposed to output a pseudo-random bit string of length N, given a seed s.

It is NOT supposed to guarantee to output the set of bit strings {b1[0:n], b2[0:n], ... for small n} given a set of seeds {s1, s2, ...}.

To clarify, here is the underlying behavior:

>>> from random import seed, random
>>> for i in range(1000):
...     seed(i); print random()
... 
0.730967788633
0.730878197405
0.731146941285
0.731057364959
0.730609460976
0.730519869749
0.730788621079
0.730699037303
0.73025113332
0.730161549544
0.730430293423
0.730340717097
0.729892805664
0.729803221888
0.730071965767
0.729982389441
0.732401084355
0.732311508029
0.732580251909
0.732490660682
[...]

Note the similarities in the one-tenth and one-hundredth places.

In other words, what you are doing seem to be asking for a higher order randomness for which the base PRNG is not suited.
msg7963 (view) Author: Frederik De Bleser (fdb) Date: 2013-03-23.00:45:45
As you probably are aware, CPython returns totally different values for the same code:

0.844421851525
0.134364244112
0.956034271889
0.237964627092
0.236048089737
0.62290169489
...

I'm not sugesting each random seed should return the same value in Jython and CPython. However, code depending on CPython's random behaviour will return skewed results: I've been bitten by this bug myself.

BTW how do we get something that resembles CPython's random behaviour in Jython?
msg8512 (view) Author: Jim Baker (zyasoft) Date: 2014-05-22.00:01:27
We are not going to reproduce this implementation dependent behavior on Jython. There are far better ways of getting more entropy in the system.
History
Date User Action Args
2014-05-22 00:01:27zyasoftsetstatus: open -> closed
resolution: wont fix
messages: + msg8512
nosy: + zyasoft
2013-03-23 00:45:46fdbsetmessages: + msg7963
2013-03-22 23:57:52santa4ntsetnosy: + santa4nt
messages: + msg7962
versions: + Jython 2.7, - Jython 2.5
2013-02-25 19:30:00fwierzbickisetpriority: normal
nosy: + fwierzbicki
versions: + Jython 2.5, - 2.5.2
2011-11-16 15:05:53fdbsetfiles: + random-seed.py
messages: + msg6721
2011-11-16 15:01:18fdbcreate