Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17900
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'assign': 0.04; 'happily': 0.07; 'used.': 0.07; "(i'm": 0.09; 'subject:string': 0.09; 'tags,': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail-iy0-f174.google.com': 0.13; 'better?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instance;': 0.16; 'roy': 0.16; 'mon,': 0.16; 'wrote:': 0.18; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'objects,': 0.23; 'string': 0.24; 'random': 0.28; 'message-id:@mail.gmail.com': 0.28; 'sun,': 0.30; 'specified': 0.31; 'subject:?': 0.31; 'sort': 0.33; 'actually': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'size,': 0.34; 'something': 0.35; 'acceptable': 0.37; 'combination': 0.37; 'received:google.com': 0.37; 'steven': 0.38; 'received:209.85': 0.38; 'should': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; 'leading': 0.62; '26,': 0.67; 'alphanumeric': 0.67; 'million': 0.76; '-0500,': 0.84; '12:48': 0.84; 'technique': 0.93; 'absolutely': 0.98 |
| 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=I51P+B+IOAJpC+uw2aTV4w/Bbcip9zKfDwfuloiC0S8=; b=BMOmJulFozcxMBJi5yX5wb9IFpLx4kNT2Cp8oYkeoB+1oWiELHNZV6ayM8On3pAwhP On+jRaKDGy+UNpgrdXiwQOToEv1dg1wQy+ip6AfxNb1Kk687IZvtr1uD87tapnTReo0X p32E+hIF3yrOkz9jh8ViS6pW7wcAu7wD0Lix8= |
| MIME-Version | 1.0 |
| In-Reply-To | <4ef7299f$0$29973$c3e8da3$5496439d@news.astraweb.com> |
| References | <roy-EDF7D2.08304625122011@news.panix.com> <4ef7299f$0$29973$c3e8da3$5496439d@news.astraweb.com> |
| Date | Mon, 26 Dec 2011 00:54:40 +1100 |
| Subject | Re: Random string of digits? |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.4070.1324821283.27778.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1324821283 news.xs4all.nl 6843 [2001:888:2000:d::a6]:45812 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:17900 |
Show key headers only | View raw
On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> 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 something better? > > '%20d' % random.randint(0, 10**20-1) I should mention that this sort of thing is absolutely acceptable in situations where you don't actually need that level of randomness; if you want to assign 20-digit numbers to each of ten million objects, you can happily use something that's only really random to fifteen. I use this technique with base 36 numbers to generate arbitrary alphanumeric strings to use as message tags, for instance; fill out a specified field size, even though not every combination will actually be used. ChrisA
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