Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'bits': 0.07; 'option,': 0.07; 'url:py': 0.07; '32-bit': 0.09; 'subject:string': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'justify': 0.16; 'random.': 0.16; 'url:hg': 0.16; 'mon,': 0.16; 'wrote:': 0.18; 'int': 0.18; 'source.': 0.18; 'tells': 0.21; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '64-bit': 0.23; 'happen.': 0.23; 'random': 0.28; 'bit': 0.28; 'message-id:@mail.gmail.com': 0.28; 'anyway.': 0.29; 'source,': 0.29; 'chris': 0.30; 'subject:?': 0.31; "i've": 0.31; 'source': 0.31; 'does': 0.32; 'sufficient': 0.32; 'pretty': 0.32; "can't": 0.32; 'actually': 0.33; 'that,': 0.33; 'url:default': 0.34; 'to:addr:python-list': 0.34; 'url:python': 0.36; 'file': 0.36; 'two': 0.37; 'received:google.com': 0.37; 'doing': 0.38; 'steven': 0.38; 'received:209.85': 0.38; 'easier': 0.38; 'url:org': 0.39; 'define': 0.39; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; '26,': 0.67; 'anything,': 0.73; 'guaranteed': 0.77; 'clearer': 0.84; 'url:lib': 0.84; 'underneath': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=S2Cs3SjObGz3NfbkOY4zs3fw4XZJISVUEJ4ZBmkJQM0=; b=R0jxLv7hx57X4/FR6lpy4JfU9H5+MUOY7xykGxtwmJQKRxnxRarLSL76xnV8MDDRnJ c4rLXSTOHY4zeMp0dGJyoL0O45KvRNH1owobSytEUXRtyo8uTlAnsjA3hLQWfgbCrZj3 gVsE+aIYei7rzP5Ruf4OCS9FxFVTPQw6XP3Ks= MIME-Version: 1.0 In-Reply-To: <4ef74572$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <4ef7299f$0$29973$c3e8da3$5496439d@news.astraweb.com> <4ef74572$0$29973$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 26 Dec 2011 03:11:56 +1100 Subject: Re: Random string of digits? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324829519 news.xs4all.nl 6933 [2001:888:2000:d::a6]:51348 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17917 On Mon, Dec 26, 2011 at 2:46 AM, Steven D'Aprano wrote: > Use the Source, Luke, er, Chris :) > > If I've read the source correctly, randint() will generate sufficient > bits of randomness to ensure that the entire int is random. > > http://hg.python.org/cpython/file/default/Lib/random.py I prefer not to rely on the source. That tells me what happens, not what's guaranteed to happen. However... bit of poking around can't hurt. That file doesn't actually justify anything, because random.Random() does not define getrandbits() - that, it seems, comes from _random(); turns out that getrandbits is actually doing pretty much the same thing I suggested: http://hg.python.org/cpython/file/745f9fd9856d/Modules/_randommodule.c#l371 Need a 64-bit random number? Take two 32-bit numbers and concatenate. So, it's going to be easier and clearer to just take the simple option, since it's actually doing the same thing underneath anyway. ChrisA