Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #92236
| References | <87oaksowwg.fsf@Equus.decebal.nl> <1451048.pW9z17ilMA@PointedEars.de> |
|---|---|
| Date | 2015-06-07 21:51 +1000 |
| Subject | Re: Testing random |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.242.1433677915.13271.python-list@python.org> (permalink) |
On Sun, Jun 7, 2015 at 8:40 PM, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote: > Cecil Westerhof 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) > > As there is no guarantee that every number will occur randomly, using a > dictionary at first should be more efficient than a list: Hmm, I'm not sure that's actually so. His code is aiming to get 'multiplier' values in each box; for any serious multiplier (he starts with 10 in the main code), you can be fairly confident that every number will come up at least once. The distribution of numbers won't ever be perfectly even, but you'd expect it to be reasonably close. I have a similar routine on my Dungeons & Dragons server; since a roll of a twenty-sided dice is crucial to most of the game, I have a simple tester that proves to people that the in-built dice roller is fair. Its output looks like this: > roll test 1: 10017 2: 10003 3: 9966 4: 9728 5: 10088 6: 9888 7: 10087 8: 9971 9: 10052 10: 10061 11: 10130 12: 9942 13: 10062 14: 10075 15: 10050 16: 9948 17: 9880 18: 10052 19: 9995 20: 10005 Standard deviation: 90.18 (0.90%) This is about equivalent to test_random(20), and as you see, he and I both picked a multiplier of 10K to use by default. (I call the parameters "max" and "avg" rather than "length" and "multiplier", but they have the exact same semantics.) The hard part is figuring out what "looks reasonable"; a true RNG could legitimately produce nothing but 7s for the entire run, it's just extremely unlikely. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Testing random Cecil Westerhof <Cecil@decebal.nl> - 2015-06-07 08:27 +0200
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 12:40 +0200
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-07 21:51 +1000
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 17:51 +0200
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-08 02:25 +1000
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 18:36 +0200
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-08 02:44 +1000
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 20:23 +0200
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-08 04:52 +1000
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 21:41 +0200
Re: Testing random Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-07 22:08 +0300
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 21:29 +0200
Re: Testing random random832@fastmail.us - 2015-06-07 15:44 -0400
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 22:09 +0200
Re: Testing random random832@fastmail.us - 2015-06-07 16:41 -0400
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 22:59 +0200
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-08 11:26 +1000
Re: Testing random random832@fastmail.us - 2015-06-07 21:34 -0400
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-08 11:42 +1000
Re: Testing random MRAB <python@mrabarnett.plus.com> - 2015-06-08 02:49 +0100
Re: Testing random random832@fastmail.us - 2015-06-07 21:57 -0400
Re: Testing random Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-08 10:40 +0300
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-10 19:03 +0200
Re: Testing random sohcahtoa82@gmail.com - 2015-06-10 10:52 -0700
Re: Testing random Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-10 23:00 +0300
Re: Testing random Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-10 12:02 -0600
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-12 23:32 +0200
Re: Testing random alister <alister.nospam.ware@ntlworld.com> - 2015-06-12 21:46 +0000
Re: Testing random random832@fastmail.us - 2015-06-12 17:52 -0400
Re: Testing random Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-12 16:00 -0600
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-13 00:09 +0200
Re: Testing random sohcahtoa82@gmail.com - 2015-06-12 15:55 -0700
Re: Testing random random832@fastmail.us - 2015-06-12 18:57 -0400
Re: Testing random Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-13 08:53 +0100
Re: Testing random random832@fastmail.us - 2015-06-10 14:26 -0400
Re: Testing random Ned Batchelder <ned@nedbatchelder.com> - 2015-06-07 14:21 -0700
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-16 21:18 +0200
Re: Testing random random832@fastmail.us - 2015-06-16 16:23 -0400
Re: Testing random Ned Batchelder <ned@nedbatchelder.com> - 2015-06-16 13:48 -0700
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-16 23:57 +0200
Re: Testing random sohcahtoa82@gmail.com - 2015-06-16 15:30 -0700
Re: Testing random Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-16 16:58 -0600
Re: Testing random Laura Creighton <lac@openend.se> - 2015-06-17 11:28 +0200
Re: Testing random Ned Batchelder <ned@nedbatchelder.com> - 2015-06-16 16:26 -0700
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-17 01:45 +0200
Re: Testing random sohcahtoa82@gmail.com - 2015-06-16 17:36 -0700
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-17 11:01 +1000
Re: Testing random Ethan Furman <ethan@stoneleaf.us> - 2015-06-16 18:32 -0700
Re: Testing random Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-17 09:41 +0100
Re: Testing random Grant Edwards <invalid@invalid.invalid> - 2015-06-17 14:04 +0000
Re: Testing random Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-17 09:01 -0600
Re: Testing random MRAB <python@mrabarnett.plus.com> - 2015-06-17 01:42 +0100
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-17 08:53 +0200
Re: Testing random Christian Gollwitzer <auriocus@gmx.de> - 2015-06-17 09:22 +0200
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-17 17:28 +1000
Re: Testing random Tim Golden <mail@timgolden.me.uk> - 2015-06-17 08:30 +0100
Re: Testing random Cecil Westerhof <Cecil@decebal.nl> - 2015-06-17 11:57 +0200
Re: Testing random Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-17 01:36 +0000
Re: Testing random Laura Creighton <lac@openend.se> - 2015-06-17 12:33 +0200
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-17 22:47 +1000
Re: Testing random Laura Creighton <lac@openend.se> - 2015-06-17 15:50 +0200
Re: Testing random Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-17 01:35 +0000
Re: Testing random Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-17 07:41 +0300
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-08 11:11 +1000
Re: Testing random Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-07 11:07 -0600
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-08 03:20 +1000
Re: Testing random "C.D. Reimer" <chris@cdreimer.com> - 2015-06-07 10:36 -0700
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-08 04:28 +1000
Re: Testing random Chris Angelico <rosuav@gmail.com> - 2015-06-08 04:40 +1000
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-08 04:24 +1000
Re: Testing random Jonas Wielicki <jonas@wielicki.name> - 2015-06-07 12:41 +0200
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-07 22:52 +1000
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-07 23:06 +1000
Re: Testing random Peter Otten <__peter__@web.de> - 2015-06-07 15:35 +0200
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 18:36 +0200
Re: Testing random Peter Otten <__peter__@web.de> - 2015-06-07 18:48 +0200
Re: Testing random Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 22:15 +0200
Re: Testing random Steven D'Aprano <steve@pearwood.info> - 2015-06-08 11:35 +1000
Re: Testing random Christian Gollwitzer <auriocus@gmx.de> - 2015-06-07 14:53 +0200
Re: Testing random Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-07 11:04 -0400
csiph-web