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


Groups > comp.lang.python > #4197

Re: how to do random / SystemRandom switch

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.mixmin.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail
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 Sat, 30 Apr 2011 14:22:59 +0200
Organization A newly installed InterNetNews server
Message-ID <ipguv6$8ba$1@r03.glglgl.eu> (permalink)
References <ipgjm6$kdv$1@speranza.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
User-Agent Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8
In-Reply-To <ipgjm6$kdv$1@speranza.aioe.org>
Lines 27
NNTP-Posting-Date 30 Apr 2011 14:30:04 CEST
NNTP-Posting-Host 1712af42.newsspool2.arcor-online.net
X-Trace DXC=YM<6[86H5V<^cW`WBF>WQ<A9EHlD;3Yc24Fo<]lROoR18kF<OcfhCO;WTBU7Rl[K`2K8FCa6^2FW2OLF_]FfFg8?2Cb>jXI@CI3
X-Complaints-To usenet-abuse@arcor.de
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4197

Show key headers only | 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