RealRand - Generate real random numbers with Ruby.

Introduction

A lot of algorithms in cryptography etc. depend on good random numbers, i.e. random numbers that are "real" random and not just generated by a so called pseudo-random generator.

You cannot create real random numbers using a computer and an algorithm. Only nature creates real randomness (just take a look around the next time you are surrounded by a group of people.).

Real randomness occurs e.g. in atmospheric noise, during radioactive decay, or in a lava lamp. Fortunately, you do not have to listen to an old radio the whole day or, even worse, deposit some uranium in your living room and observe it with a Geiger-Müller tube. Other people do so (in a slightly modified manner, of course) and they kindly make their results public.

There are at least the following web sites, that offer real random numbers for free:

All these real random numbers can be requested via different HTTP interfaces that all look very similar. E.g. you can request a number of random bytes from any of the web sites above.

This project encapsulates all these very similar but still different HTTP interfaces and offers simple Ruby interfaces to get real random numbers from all the web sites mentioned above.

Installation

This library requires at least Ruby 1.8.x.

RealRand is available as a Gem and the easiest way to install it is to:

      gem install realrand

If you do not want to use RubyGem you have to download RealRand. After unpacking the distribution run the following commands from the main directory:

  ruby install.rb config
  ruby install.rb setup
  ruby install.rb install

Usage

Once RealRand is installed and your internet connection is up, generating real random numbers is a piece of cake:

  require 'random/online'

  generator1 = RealRand::RandomOrg.new
  puts generator1.randbyte(5).join(",")
  puts generator1.randnum(100, 1, 6).join(",")  # Roll the dice 100 times.
        
  generator2 = RealRand::FourmiLab.new
  puts generator2.randbyte(5).join(",")
  # randnum is not supported.

  generator3 = RealRand::EntropyPool.new
  puts generator3.randbyte(5).join(",")
  # randnum is not supported.

Limits

The following limits do apply to the different functions:

Proxies

If you have to use a HTTP proxy, you can set it as follows:

  require 'random/online'

  generator1 = RealRand::RandomOrg.new
  generator1.proxy_host = 'your.proxy.here'
  generator1.proxy_port = 8080
  generator1.proxy_usr  = 'your.user.here'
  generator1.proxy_pwd  = 'secret'
  puts generator1.randbyte(5).join(",")
  puts generator1.randnum(100, 1, 6).join(",")  # Roll the dice 100 times.

Important Note

All the services used in this library are offered for free by their maintainers. So, PLEASE, have a look at their web sites and obey to their rules, if you use their service.

Contact

If you have any suggestions or want to report bugs, please contact me.


Copyright © 2003-2014 by Maik Schmidt.