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


Groups > comp.lang.python > #17917

Re: Random string of digits?

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>
Date 2011-12-26 03:11 +1100
Subject Re: Random string of digits?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4077.1324829519.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Dec 26, 2011 at 2:46 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> 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

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