cross-version random class

3 views
Skip to first unread message

smichr

unread,
May 27, 2012, 11:14:49 AM5/27/12
to sy...@googlegroups.com
In working on  https://github.com/sympy/sympy/pull/1310 I have a suggestion that I throw out as an FYI:

1) when writing a function that utilizes the random module, be sure to provide a seed argument so the function can be tested.
2) don't re-seed the module with the seed, create a new instance:

yes

if seed is not None:
  rand = random.Random(seed)
else:
  rand = random
...
rand.randint(1, 10) # or whatever

no

random.seed(seed)
...
random.randint(1, 10)

3) If you want the same behavior of random features for a given seed in py 2.5 through 3.2 please review the cited pull request. :-)

/c
Reply all
Reply to author
Forward
0 new messages