Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.python Subject: Re: Testing random Date: Sun, 07 Jun 2015 18:36 +0200 Organization: PointedEars Software (PES) Lines: 28 Message-ID: <1586765.9ka6YhQpJC@PointedEars.de> References: <87oaksowwg.fsf@Equus.decebal.nl> <55743ea4$0$13004$c3e8da3$5496439d@news.astraweb.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1433695121 19721 eJwFwQcBwEAIBDBLZRxDDuPxL6EJxMjG1WCKw1GQRiZfYWXCU2mt+5GcVz7aMRz3V3IK3v0BErgROQ== (7 Jun 2015 16:38:41 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 7 Jun 2015 16:38:41 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNx8EBwCAIA8CVwJCg4yji/iO09ztCrsoQFXx8RSganRj7Wgwt89pXCS8fmkRrQghndv7NNpxFFk7V9g8jbRQ9 Cancel-Lock: sha1:r0toQzrDbYKsFjjWkjZmDKPf8dk= X-NNTP-Posting-Host: eJwNwgERwDAIA0BLhRA65Kyk+Jew3T+Rlr0jmcH5BbRWT1O6W2eAR+F2FzDiW5Tve4hyZhk+KIURAQ== Xref: csiph.com comp.lang.python:92270 Peter Otten wrote: > Steven D'Aprano wrote: >>> I wrote a very simple function to test random: >>> def test_random(length, multiplier = 10000): >>> number_list = length * [0] >>> for i in range(length * multiplier): >>> number_list[random.randint(0, length - 1)] += 1 >>> minimum = min(number_list) >>> maximum = max(number_list) >>> return (minimum, maximum, minimum / maximum) >> >> Putting aside the timing aspects, your frequency calculations are not >> done in a very Pythonic manner. > > I would agree if the frequency table were sparse, i. e. many indices with > > number_list[index] == 0 > > but that's not the case with on average 10000 hits per index. A common misconception. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.