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


Groups > comp.lang.python > #17943

Re: Random string of digits?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'override': 0.07; 'bits.': 0.09; 'subject:string': 0.09; 'received:209.85.210.174': 0.13; 'received:mail-iy0-f174.google.com': 0.13; '"new': 0.16; '53-bit': 0.16; 'arbitrarily': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guaranteed.': 0.16; 'ranges.': 0.16; 'mon,': 0.16; 'wrote:': 0.18; '2.x': 0.18; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'assumes': 0.23; 'documented': 0.23; 'produces': 0.23; 'explains': 0.24; 'code.': 0.26; 'module': 0.26; 'function': 0.27; 'random': 0.28; 'separate': 0.28; '(and': 0.28; 'message-id:@mail.gmail.com': 0.28; 'pm,': 0.29; 'precision': 0.30; 'subject:?': 0.31; 'source': 0.31; "didn't": 0.31; 'does': 0.32; "can't": 0.32; "isn't": 0.33; 'actually': 0.33; 'this.': 0.33; 'that,': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'all.': 0.34; 'running': 0.35; 'but': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'somewhat': 0.38; 'steven': 0.38; 'allows': 0.38; 'some': 0.38; 'received:209.85': 0.38; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; 'your': 0.61; 'leading': 0.62; '26,': 0.67; 'stated': 0.68; 'supply': 0.69; 'gain': 0.75; '2:00': 0.84; 'disagreement': 0.84; 'generator,': 0.84; 'public,': 0.84
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:content-transfer-encoding; bh=ndiPmwC5+dfJGPEKfvGcGwMr6M8uEY8T4pDQqS8qPow=; b=unmo6wppx4C69OQkR3opSpBv3S2wlPOAHX5hQjykn9jDT7EtUQkTB3yS27wpqxUSbm J7jrGYNEc84F18uatRLhjTHMtzfgQnVf9rMVmmggTyr4K4B94tIFmVZLeFY4iHeqrZ6J 7JY94z8LwEZ/SRXY5tren3C8APpY3IevdSJgg=
MIME-Version 1.0
In-Reply-To <4ef7e337$0$29973$c3e8da3$5496439d@news.astraweb.com>
References <roy-EDF7D2.08304625122011@news.panix.com> <4ef7299f$0$29973$c3e8da3$5496439d@news.astraweb.com> <mailman.4070.1324821283.27778.python-list@python.org> <4ef74572$0$29973$c3e8da3$5496439d@news.astraweb.com> <mailman.4077.1324829519.27778.python-list@python.org> <4ef75afc$0$29973$c3e8da3$5496439d@news.astraweb.com> <roy-800FCE.12412925122011@news.panix.com> <4ef7e337$0$29973$c3e8da3$5496439d@news.astraweb.com>
Date Mon, 26 Dec 2011 14:43:35 +1100
Subject Re: Random string of digits?
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4092.1324871017.27778.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324871017 news.xs4all.nl 6926 [2001:888:2000:d::a6]:49659
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17943

Show key headers only | View raw


On Mon, Dec 26, 2011 at 2:00 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> The implementation of getrandbits is not documented at all. You would
> have to read the C source of the _random module to find out how the
> default pseudo-random number generator produces random bits. But note the
> leading underscore: _random is a private implementation detail.
>
> However the existence and use of random.Random.getrandbits is public,
> documented, and guaranteed.

It's that last line where I find disagreement between documentation
and source code.

"""Class Random can also be subclassed if you want to use a different
basic generator of your own devising: in that case, override the
random(), seed(), getstate(), and setstate() methods. Optionally, a
new generator can supply a getrandbits() method — this allows
randrange() to produce selections over an arbitrarily large range."""

My reading of this is that, if I were to write my own generator, I
could provide that method and gain perfection. It's not until you dig
somewhat that you find out that the default generator actually does
provide getrandbits, meaning that the default randrange can actually
be used for arbitrarily large ranges. Yes, it IS documented, but in
separate places and somewhat as an afterthought; in the 2.x
documentation it's shown as "new in 2.4", which explains this.

Unfortunately my brain isn't really running on all cylinders at the
moment and I can't come up with a better wording, but is there some
way this could be stated up in the same top paragraph that explains
about 53-bit precision and 2**19937-1 period? That's where I got my
original information from; I didn't go down to the individual function
definitions, which is the only place that it's stated that the
Mersenne Twister does include getrandbits (and which assumes that
you've read the top section that states that Mersenne Twister is the
default implementation).

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Random string of digits? Roy Smith <roy@panix.com> - 2011-12-25 08:30 -0500
  Re: Random string of digits? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-25 13:48 +0000
    Re: Random string of digits? Chris Angelico <rosuav@gmail.com> - 2011-12-26 00:54 +1100
      Re: Random string of digits? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-25 15:46 +0000
        Re: Random string of digits? Chris Angelico <rosuav@gmail.com> - 2011-12-26 03:11 +1100
          Re: Random string of digits? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-25 17:18 +0000
            Re: Random string of digits? Roy Smith <roy@panix.com> - 2011-12-25 12:41 -0500
              Re: Random string of digits? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-25 11:50 -0800
              Re: Random string of digits? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-26 03:00 +0000
                Re: Random string of digits? Chris Angelico <rosuav@gmail.com> - 2011-12-26 14:43 +1100
                Re: Random string of digits? Roy Smith <roy@panix.com> - 2011-12-25 23:17 -0500
                Re: Random string of digits? Chris Angelico <rosuav@gmail.com> - 2011-12-26 15:26 +1100
    Re: Random string of digits? Serhiy Storchaka <storchaka@gmail.com> - 2011-12-25 19:32 +0200
  Re: Random string of digits? Chris Angelico <rosuav@gmail.com> - 2011-12-26 00:50 +1100
    Re: Random string of digits? Roy Smith <roy@panix.com> - 2011-12-25 09:21 -0500
      Re: Random string of digits? Chris Angelico <rosuav@gmail.com> - 2011-12-26 01:51 +1100
        Re: Random string of digits? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-25 15:27 +0000
  Re: Random string of digits? Chris Angelico <rosuav@gmail.com> - 2011-12-26 00:51 +1100
  Re: Random string of digits? Peter Otten <__peter__@web.de> - 2011-12-25 16:21 +0100

csiph-web