how to do random / SystemRandom switch
Thomas Rachel
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Sat Apr 30 08:22:59 EDT 2011
Am 30.04.2011 11:10 schrieb Matthias Kievernagel:
> In my top-level script I want to select if my program
> is to use random.xxx functions or the random.SystemRandom.xxx
> ones.
On which criteria do you fix that?
Anyway, you could use a module myrandom.py:
import random
if use_sys:
randobj = random.SystemRandom()
else:
randobj = random.Random()
and then use
from myrandom import randobj as random
and then use random's methods (randrange, random, whatever), no matter
where they come from.
Thomas
More information about the Python-list
mailing list