Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17905
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Random string of digits? |
| Date | 2011-12-25 09:21 -0500 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-895E70.09213425122011@news.panix.com> (permalink) |
| References | <roy-EDF7D2.08304625122011@news.panix.com> <mailman.4068.1324821046.27778.python-list@python.org> |
In article <mailman.4068.1324821046.27778.python-list@python.org>, Chris Angelico <rosuav@gmail.com> wrote: > "%020d"%random.randint(0,99999999999999999999) > (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 entropy involved here is the ever increasing amount of it between my ears. It never occurred to me to try that :-) > For your actual task, I'd be inclined to take ten digits, twice, and > not bother with join(): > > '%010d%010d'%(random.randint(0,9999999999),random.randint(0,9999999999)) > > Looks a little ugly, but it works! And only two random number calls > (which can be expensive). Hmmm. In my case, I was looking more to optimize clarity of code, not speed. This is being used during account creation on a web site, so it doesn't get run very often. It turns out, I don't really need 20 digits. If I can count on >>> "%020d" % random.randint(0,999999999999999) to give me 15-ish digits, that's good enough for my needs and I'll probably go with that. Thanks.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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