hn-classics/_stories/2010/16034353.md

15 KiB
Raw Permalink Blame History

created_at title url author points story_text comment_text num_comments story_id story_title story_url parent_id created_at_i _tags objectID year
2017-12-30T08:07:21.000Z How to test a random number generator (2010) https://www.johndcook.com/blog/2010/12/06/how-to-test-a-random-number-generator-2/ Cieplak 68 42 1514621241
story
author_Cieplak
story_16034353
16034353 2010

Source

How to test a random number generator

John D. Cook

Skip to content

(832) 422-8646

Contact

How to test a random number generator

Posted on 6 December 2010 by John

Last year I wrote a chapter for OReillys book Beautiful Testing (ISBN 0596159811). The publisher gave each of us permission to post our chapters online, and so here is Chapter 10: How to test a random number generator.

Beautiful Testing: Leading Professionals Reveal How They Test

Categories : Software development Statistics

Tags : Books Probability and Statistics Programming Quality RNG

Bookmark the permalink

Post navigation

Previous PostMilitary intelligence from serial numbers

Next PostMaybe you only need it because you have it

24 thoughts on “How to test a random number generator”

  1. Wen Chen

6 December 2010 at 14:59

hi john,

thank you for the chapter.

ive been following your blog this year. just wondering if you were planning to write a numerical computing book. or if there are books you would recommend.

  1. John

6 December 2010 at 15:08

Wen, Thanks. I dont have any plans to write a numerical computing book.

One of my favorite numerical books is an old one, Numerical Methods that Work. Its not a cookbook. Its a book on how to think about numerical computing.

  1. Hansi

6 December 2010 at 15:45

Thanks for that, great read. Any suggestions for a programming recipe book that covers the same or similar tests?

  1. John

6 December 2010 at 15:49

Hansi: You can read more about some of the tests in Knuths Seminumerical Algorithms, TAOCP volume 2. You might also check Numerical Recipes.

  1. Hansi

6 December 2010 at 15:54

Great, Im pretty sure there is a copy of Knuths TAOCP at work. Ill have a look tomorrow.

Thanks again.

  1. SteveBrooklineMA

7 December 2010 at 13:07

Actons book is an entertaining read, but how well has it stood up? Computing power and software have advanced so much in the 40 years since he wrote it, its not clear that the cautionary tales he tells are still as relevant. He might tell you a story of how 20 minutes of thought could have saved an investigator 20 hours of computing time. Now however, that same computer program, or a more robust off-the-shelf one, might run in a couple of seconds. So why think? 😉

You could argue that the complexity of problems has grown as computing power has grown, so that thought is as necessary as ever. However, I might counter that more complex problems are difficult to tackle in the way the problems in Actons book can be tackled. Dont the problems in Actons book seem rather… quaint?

I think if I were going to recommend a book for learning practical, hands-on numerical computing, I would recommend Numerical Recipes.

  1. John

7 December 2010 at 14:52

I think the principles in Actons book are still valuable, though the specifics are outdated. For example, most computing is now done in double precision rather than single precision. Loss of accuracy still happens when youre not careful; you see the same problems but for a smaller range of inputs.

Acton doesnt deal with sorting, but bubble sort is still slower than heap sort, even though both are instantaneous for small data sets. The idea of what is “small” has changed over time, but the principle remains.

However, there is one important area that Acton doesnt address at all if I remember correctly, and that is random methods: random number generation, Monte Carlo integration, etc. These methods have become far more common in practice (at least in my practice :)).

  1. SteveBrooklineMA

7 December 2010 at 15:11

I think the most out-of-date aspect of Actons book is that it has an entire chapter on Fourier Series, but doesnt mention the FFT.

  1. mat roberts

8 December 2010 at 06:26

I liked the chapter, in particular the line “The point is not only to test the quality of the library itself, but also to test the user's understanding of the library.”

Im surprised you didnt recommend plotting the data and taking a look at it always seems valuable.

  1. Pingback: igorbrejc.net » Fresh Catch For December 12th

  2. Jason B

11 January 2011 at 11:57

I like this one for testing RNGs.

http://portal.acm.org/citation.cfm?doid=1268776.1268777

There is a nice battery of tests ready to go in C++. If the RNG makes it through that in good shape, great.

One kind of disturbing aspect of the chapter is that its existence implies software developers should be going off and writing their own RNGs. Why bother when there are good ones out there that have been through very rigorous scrutiny?

The problem with plotting random data, especially uniform data, is that we cant visually detect any meaningful flaws in the data.

  1. John

11 January 2011 at 12:52

Jason: I dont want to encourage anyone to develop their own uniform random number generation algorithm. But some people will need to implement existing algorithms in new languages. And even more people will need to transform a uniform random sequence into a sequence with another distribution, maybe a distribution unique to their problem.

  1. Jason B

11 January 2011 at 13:18

John,

Thanks for the reply. I hope the readership of the book takes your perspective as well!

Jason

  1. Khameel

28 September 2011 at 04:41

Hi John,

Even though, this post is no longer a current subject of discussion. I write to appreciate your efforts in putting together a collection of numerical gems in this blog. I have benefitted quite a lot from this blog. Remain blessed.

From Singapore.

  1. Pingback: Pseudo-Random vs. Random Numbers in R at johnramey

  2. Jim Dukelow

26 March 2012 at 11:20

Hi John,

I share your love of Actons book and Steves recognition that it is, in some respects, outdated. I like Actons mindset of thinking about what you are trying to calculate and being willing to find different algorithms when you are up against the potential for or reality of catastrophic loss of precision. The original book had the title embossed into the red cover, with the letters highlighted in silver. Also embossed, but not highlighted, was the word “usually”. Lovely.

  1. Pingback: Random number sequence overlap — The Endeavour

  2. Pingback: Statistical Toolbox: The Kolmogorov-Smirnov Test AK Tech Blog

  3. Pingback: Random or not? That is the question! « Holy Hash!

  4. Matthew Wyatt

4 December 2012 at 12:01

Just came across this link from the CompSciFact twitter account. Are you aware of the typo in the first footnote on page 131? The word “lest” should be “least”, I believe. I know this is a few years old, so maybe its not helpful now.

  1. Ben Bradley

4 December 2012 at 12:18

Im reminded that sometimes, even though you may THINK you want random, it may not be what you want. From this tweet from earlier today, what the tweeter really wants is “random, or even a cheap approximation, unless the current entry has come up TOO recently:” “iPad, I appreciate your shuffle. I do. And you know I like Enya “The Longships.” But not as every third song. #shuffleparalysis”

And I hope Im not too much of an insufferable pedant in pointing out that this is about testing pseudo-random number generators (PRNG) a “true” random number generator will (almost?!) always pass such tests.

  1. Pingback: Comment tester un générateur de nombres aléatoires | L'Endormitoire

  2. Pingback: Random is as random does

  3. Pingback: New top story on Hacker News: How to test a random number generator (2010) ÇlusterAssets Inc.,

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment

Notify me of followup comments via e-mail

Name *

Email *

Website

Search for:

John D. Cook

John D. Cook, PhD

Latest Posts

Categories

CategoriesSelect CategoryBusinessClinical trialsComputingCreativityGraphicsMachine learningMathMusicPowerShellPythonScienceSoftware developmentStatisticsTypographyUncategorized

| ----- | | Subscribe to blog by email | Subscribe via email | | RSS icon | Subscribe via RSS | | Newsletter icon | Monthly newsletter |

John D. Cook

© All rights reserved.

Search for: