Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; "(i'm": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:string': 0.09; 'better?': 0.16; 'roy': 0.16; 'wrote:': 0.18; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'string': 0.24; 'random': 0.28; 'sun,': 0.30; 'subject:?': 0.31; 'header:User- Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'something': 0.35; '8bit%:86': 0.37; 'steven': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.40; '2011': 0.61; 'leading': 0.62; 'skip:\xd0 20': 0.77; '-0500,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: Random string of digits? Date: Sun, 25 Dec 2011 19:32:27 +0200 References: <4ef7299f$0$29973$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 79.124.152.23 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111220 Thunderbird/9.0 In-Reply-To: <4ef7299f$0$29973$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 10 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324834371 news.xs4all.nl 6885 [2001:888:2000:d::a6]:40078 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17924 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' % random.randint(0, 10**20-1) '%020d' % random.randrange(10**20)