Sunday, July 22, 2007

Quantum Random Bit Generator Service

Random Bits from Zagreb, Croatia

Once in a while, something worthy of being called a Web Service comes on the scene, that makes the internet a better place. Radomir Stevanović, B.Sc., a Research assistant, PhD student, at the Ruder Boskovic Institute, Centre for Informatics and Computing, located in Zagreb, Croatia has put up a wonderful resource to aid researchers all over the world. It is called the Quantum Random Bit Generator Service. Rather than using cumbersome equipment to generate random numbers from quantum events yourself, Radomir has made a very simple Web Service that takes requests for N bits of random numbers, pre-formated in any of the usual C integer and float types, which you can choose from when you make the request. He even provides source code for the interface.

As my readers are aware, this blog is about Scheme. So you may be waiting for the punch line, "I ported the interface to Scheme." Well, not yet. I returned to my roots as a C++ programmer, and merely ported the supplied C++ code to the Mac OS X, using the Intel C/C++ compiler v10.0.016, which allows me to generate code specifically optimized for the two dual core Intel Xeon processors under the hood. The gcc compiler that Apple ships with their Mac Pro's doesn't have that capability. The port went splendidly. I just had to clean up a couple of the author's typos, you know the difference between `=' and `==' in C++, and how easy, and dangerous, it is to get them wrong. It was fun hacking up C++ again, but I don't miss those kind of silly mistakes that can take you hours to find. Lucky for me the Intel compiler provided a very prominent warning, so the credit really goes to the compiler.

After I hard coded into my version my account name, password, as well as changing all the default values to the ones I would typically use, and got it compiled without any warnings, it work the first time like a charm. There is a quota system in place, however, for now it appears that they have got everyone set to unlimited. As I intend it to merely replace a call to the pseudo random number generator in Scheme with a request to their service, I can't imagine I'll be a noticeable hit to the bandwidth of their server, even if they did have a limit. When I hack up the Scheme version I'll post the code here.

Their site proudly displays their average entropy, and the number of gigabytes that they've served up, as well as the average of all bytes served, which, not surprisingly is near dead on 127. And they have plans for even easier access to their service in the future. For now, they lack a secure protocol for obtaining your bits, which means nothing, unless you were going to use it to generate cryptograms with their data. However, they have secure access in the works. But for scientific work, this is already a real win. I hope they keep their non-secure service freely available to scientists, and make their money off the secure access.

Oh, and by the way, be prepared to solve some differential equations before you can get an account. I thought that was a nice touch; instead of typing in goofy looking letters to prove your human, you have to do a math problem. At their site, you have to prove you have mathematical competency as well as being human.




dasht said...


Other people, in the past, have made available many megabytes (but that's all) of off-line computed true randoms and this is a welcome improvement.

You probably already know this but two fun tricks:

Trick one is to graph true randoms and graph PRNG randoms and compare -- it doesn't take much to expose all kinds of interesting weird artifacts in the PRNG randoms. Those weird artifacts may not show up as very significant in popular measures of PRNG quality but if they are placed in nasty enough ways they can spoil your whole day of scientific computing. And, there's some rule-of-thumb law that says "nothing is accidental" -- i.e., the artifacts tend to appear around "interesting" numbers where "interesting" numbers means "mysteriously, the very place you needed there not to be these artifacts."

Trick 2 is that, given N bytes of true randoms, you can pretty trivially construct a PRNG with a cycle of N^2 or N^3 .... bytes and, for small exponents, if your problems sets need fewer than N^k randoms (and, again, you aren't doing crypto) -- you still get damn fine randoms. (You get N^K by having K randomly placed read-heads indexing into N true randoms and generating your pseudos by xoring those while advancing the read-heads. Watch out for the edge case to avoid: having two read heads at the same spot at the same time.)