Random Numbers

Introduction

In the course of working with long numbers one may require a long stream of random numbers. Here we review methods for generating them.

Irrational numbers

The digits of the irrational numbers such as π and е are randomly distributed but of course cannot be said to be truly random. they are psuedorandom in that they satisfy all of the properties of randomness but are in fact comletey predictable if we know the generating function.

Psuedonoise generators employ a fixed-length shift register that will emit a very long sequence of random numbers before they repeat exactly. If we know the exact taps of the shift register then we can predict the number sequence precisely.

Random numbers are:

  • statistically independent

  • not necessarily uniformly distributed

  • create no visible pattern in an x-y plot:

Random.org

The website https://www.random.org/arrow-up-right provides an API that any remote application can access securly to obtain true random numbers.

Random Number Widget.

The site has a little widget for generting a true random number between 1 and a maximum you specifiy. It generates the HTMarrow-up-right for you. Here is an example (change wwww to www to enable it - GitBook crashes soon after ):

The numbers generated by this widget come from RANDOM.ORG's true random number generator.

Coinflipper

The Coinflipperarrow-up-right site will generate a sequence of pictures of the coin tosses of your choice. This is all in fun.

Random Number Internet API

Referencearrow-up-right

This example will generate a series of 10 integers in the [1,6] interval:

Command Line Methods

Unix and Linux provide two system devices for generating random number streams:

An example method to generate 10 million random bytes (this takes almost one second on an early 2008 Mac Pro running 2.8 Ghz Xeon processor) on the command line is:

On Linux, /dev/urandom (where u stands for unlimited) will reuse the entropy pool rather than blocking, while /dev/random will block when the entopy pool has drained.

To generate a sequence of random numbers in the bash shell:

Random Numbers in Programming Languages

R

Referencearrow-up-right

Last updated