Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4197

Re: how to do random / SystemRandom switch

From Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Newsgroups comp.lang.python
Subject Re: how to do random / SystemRandom switch
Date 2011-04-30 14:22 +0200
Organization A newly installed InterNetNews server
Message-ID <ipguv6$8ba$1@r03.glglgl.eu> (permalink)
References <ipgjm6$kdv$1@speranza.aioe.org>

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar


Thread

Re: how to do random / SystemRandom switch Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-04-30 14:22 +0200

csiph-web