Random.org Gem

Random integers, baked fresh daily.

by Mike Green

Summary

This is my first attempt at creating a Ruby gem. It’s a really simple class that uses Random.org’s key-value interface to generate a user-specified number of random integers. It’s mostly just so I can teach myself basic gem development, but I can see it being useful in web applications that need a reliable, true random number generator.

The Random.org Gem is a module that currently contains only one class: RandomOrg::Integer, which is an interface to Random.org’s random integer generator service. Eventually it will also contain a class that generates sequences of random integers, corresponding to Random.org’s sequence generator. Obviously, the Random.org Gem requires an active internet connection to work.

Usage

Usage is pretty straightforward — the only method is new(min, max, base), where base is either 2, 8, 10, or 16. The default setting is to generate a random base 10 (decimal) integer. Right now, if you choose to generate a hexidecimal integer, it will give you a string. Mostly because I’m lazy.


	require 'random_org'
	
	int = RandomOrg::Integer.new(0, 100) # base defaults to 10
	puts int.value # That's your randomly generated integer.

Dependencies

  • Ruby Standard Library (that’s it)

About Random.org

From their website:

RANDOM.ORG offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs. People use RANDOM.ORG for holding draws, lotteries and sweepstakes, to drive games and gambling sites, for scientific applications and for art and music. The service has existed since 1998 and was built and is being operated by Mads Haahr of the School of Computer Science and Statistics at Trinity College, Dublin in Ireland.

COPYRIGHT

Copyright © 2008 Mike Green. See LICENSE for details.