Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'scripts': 0.03; 'output': 0.05; 'apps,': 0.07; 'corrections': 0.09; 'quiet': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'wrong,': 0.09; 'random': 0.14; 'benjamin': 0.16; 'components.': 0.16; 'does,': 0.16; 'expert,': 0.16; 'goes...': 0.16; 'indirectly': 0.16; 'instead:': 0.16; 'kern': 0.16; 'realising': 0.16; 'reboot': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:random': 0.16; 'underlying': 0.16; 'wrote:': 0.18; '(where': 0.19; "hasn't": 0.19; 'thu,': 0.19; '>>>': 0.22; 'header :User-Agent:1': 0.23; 'interpret': 0.24; 'typical': 0.24; 'url:dev': 0.24; "i've": 0.25; 'source': 0.25; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'external': 0.29; 'robert': 0.30; "i'm": 0.30; 'software,': 0.31; 'url:wiki': 0.31; '+0100,': 0.31; 'continually': 0.31; "d'aprano": 0.31; 'lot.': 0.31; 'steven': 0.31; 'url:wikipedia': 0.31; 'run': 0.32; 'running': 0.33; 'sources': 0.33; 'could': 0.34; 'but': 0.35; 'really': 0.36; 'doing': 0.36; 'url:org': 0.36; 'operating': 0.37; 'e.g.': 0.38; 'machines': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'generating': 0.39; 'moving': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'called': 0.40; 'users': 0.40; 'how': 0.40; 'even': 0.60; 'is.': 0.60; 'numbers': 0.61; 'skip:n 10': 0.64; 'our': 0.64; 'grab': 0.64; 'networking': 0.64; 'provide': 0.64; 'more': 0.64; 'world': 0.66; 'here': 0.66; 'minutes': 0.67; 'believe': 0.68; 'of:': 0.68; 'electrical': 0.74; 'special': 0.74; 'eco': 0.84; 'noise': 0.84; 'oscar': 0.84; 'received:202.71': 0.84; 'subject:long': 0.84; 'terrible': 0.84; 'thermal': 0.84; 'subject:very': 0.91; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: performance of script to write very long lines of random chars Date: Thu, 11 Apr 2013 16:49:07 +0530 References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 202.71.137.182 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365679158 news.xs4all.nl 2699 [2001:888:2000:d::a6]:39719 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43353 On 2013-04-11 16:20, Steven D'Aprano wrote: > On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: > >> On 11 April 2013 08:47, Steven D'Aprano >> wrote: >> >>> One thing to be aware of: urandom may run out of entropy, and then it >>> will slow down a lot. If you don't care about cryptographic randomness, >>> you could use this instead: >> >> Reading this I'm realising that I don't really know what os.urandom is. >> How exactly is it generating random numbers and what do you mean by it >> running out of entropy? > > I am not an expert, but here goes... > > Some (most?) modern operating systems provide a cryptographically strong > source of non-deterministic randomness. The non-deterministic part comes > from external "stuff", which is called "entropy". Typical sources of > entropy include network events, user key-presses, moving the mouse, and > (presumably in machines with special hardware), even thermal noise in > electrical components. > > If the OS hasn't collected enough entropy, urandom can block until it > has. This can be a problem, e.g. I've experienced issues where scripts > relying indirectly on urandom that run at system reboot can block for > minutes at a time, waiting for entropy. If those scripts run before the > networking software, and before any users log in and start running apps, > the script can block forever waiting for entropy that never arrives. > > (Where "forever" == "70 minute boot times".) > > Entropy is used and discarded, so urandom needs the OS to continually > replenish the amount of entropy. Under normal circumstances, this it > does, but if you grab lots of urandom output on a system which is > otherwise quiet and not doing anything, it could run out. > > If I've got any of this wrong, corrections will be gratefully acceptable. Just one important thing: os.urandom() does not block to wait for more entropy. Only os.random() does. http://en.wikipedia.org/wiki//dev/random -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco