Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 3:17 PM, Roy Smith wrote: > Of course it is.  Those things constitute doc bugs which need to get > fixed.  The fact that the specification is flawed does not change the > fact that it *is* the specification. Also, the specification is what can be trusted across multiple im

Re: Random string of digits?

2011-12-25 Thread Roy Smith
In article <4ef7e337$0$29973$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > And I'm afraid that you have missed my point. The above comment from the > source is from a docstring: it *is* public, official documentation. See > help(random.Random). When you wrote, "the source expl

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 2:00 PM, Steven D'Aprano 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: _r

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 12:41:29 -0500, Roy Smith wrote: > On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: >> > I prefer not to rely on the source. That tells me what happens, not >> > what's guaranteed to happen. > > Steven D'Aprano wrote: >> In this case, the source explicitly tells you

Re: Random string of digits?

2011-12-25 Thread 88888 Dihedral
Roy Smith於 2011年12月26日星期一UTC+8上午1時41分29秒寫道: > On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: > > > I prefer not to rely on the source. That tells me what happens, not > > > what's guaranteed to happen. > > Steven D'Aprano wrote: > > In this case, the source explicitly tells you that t

Re: Random string of digits?

2011-12-25 Thread Joshua Landau
On 25 December 2011 17:32, Serhiy Storchaka wrote: > 25.12.11 15:48, Steven D'Aprano написав(ла): > > On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: >> >>> I want to create a string of 20 random digits (I'm OK with leading >>> zeros). The best I came up with is: >>> ''.join(str(random.ran

Re: Random string of digits?

2011-12-25 Thread Roy Smith
On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: > > I prefer not to rely on the source. That tells me what happens, not > > what's guaranteed to happen. Steven D'Aprano wrote: > In this case, the source explicitly tells you that the API includes > support for arbitrary large ranges if

Re: Random string of digits?

2011-12-25 Thread Serhiy Storchaka
25.12.11 15:48, Steven D'Aprano написав(ла): On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: I want to create a string of 20 random digits (I'm OK with leading zeros). The best I came up with is: ''.join(str(random.randint(0, 9)) for i in range(20)) Is there something better? '%20d' % ran

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 03:11:56 +1100, Chris Angelico wrote: > 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. >>

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
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

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 00:54:40 +1100, Chris Angelico wrote: > On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano > wrote: >> On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: >> >>> I want to create a string of 20 random digits (I'm OK with leading >>> zeros).  The best I came up with is: >>> >>>

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 01:51:30 +1100, Chris Angelico wrote: > On Mon, Dec 26, 2011 at 1:21 AM, Roy Smith wrote: >> It turns out, I don't really need 20 digits.  If I can count on >> > "%020d" % random.randint(0,999) >> >> to give me 15-ish digits, that's good enough for my needs and

Re: Random string of digits?

2011-12-25 Thread Peter Otten
Chris Angelico wrote: > On Mon, Dec 26, 2011 at 12:30 AM, Roy Smith wrote: >> I want to create a string of 20 random digits (I'm OK with leading >> zeros). The best I came up with is: >> >> ''.join(str(random.randint(0, 9)) for i in range(20)) >> >> Is there something better? > > The simple opt

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 1:21 AM, Roy Smith wrote: > It turns out, I don't really need 20 digits.  If I can count on > "%020d" % random.randint(0,999) > > to give me 15-ish digits, that's good enough for my needs and I'll > probably go with that.  Thanks. I'd say you can. The info

Re: Random string of digits?

2011-12-25 Thread Roy Smith
In article , Chris Angelico wrote: > "%020d"%random.randint(0,) > (the latter gives you a string, padded with leading zeroes). But I'm > assuming that you discarded that option due to lack of entropy (ie you > can't trust randint() over that huge a range). Actually, the only

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano wrote: > On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: > >> I want to create a string of 20 random digits (I'm OK with leading >> zeros).  The best I came up with is: >> >> ''.join(str(random.randint(0, 9)) for i in range(20)) >> >> Is there

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:50 AM, Chris Angelico wrote: > The Python 2 docs [1] Forgot to provide link. Python 2: http://docs.python.org/library/random.html And same in Python 3: http://docs.python.org/py3k/library/random.html ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Random string of digits?

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:30 AM, Roy Smith wrote: > I want to create a string of 20 random digits (I'm OK with leading > zeros).  The best I came up with is: > > ''.join(str(random.randint(0, 9)) for i in range(20)) > > Is there something better? The simple option is: random.randint(0,99

Re: Random string of digits?

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 08:30:46 -0500, Roy Smith wrote: > I want to create a string of 20 random digits (I'm OK with leading > zeros). The best I came up with is: > > ''.join(str(random.randint(0, 9)) for i in range(20)) > > Is there something better? '%20d' % random.randint(0, 10**20-1) -- St

Random string of digits?

2011-12-25 Thread Roy Smith
I want to create a string of 20 random digits (I'm OK with leading zeros). The best I came up with is: ''.join(str(random.randint(0, 9)) for i in range(20)) Is there something better? -- http://mail.python.org/mailman/listinfo/python-list