Generating Sub-random Numbers

Sub-random numbers sort of look random, but they aren’t and they usually provide better coverage over an interval which is sometimes more important than having truly random data. For example, you wouldn’t use sub-random numbers for encryption, but they’d be great for performing Monte Carlo calculations. You can read more about them on the Wikipedia page for low discrepancy sequences.

Additive Recurrence

One simple technique is that of additive recurrence. You start with a seed s_{0}, and a constant \alpha. You then use the following recurrence relation:

    \[s_{i+1} = ( s_{i} + \alpha ) \mod 1\]

Below is the code, with some imports.

import scipy.stats
import scipy
import random
from pylab import *

def additive_recurrence( n ):
    s0, a = scipy.stats.uniform().rvs((2,))
    s = [ s0 ]
    for i in xrange(n):
        s.append( ( s[-1] + a ) % 1 )
    return s

n = 250
x, y = additive_recurrence(n), additive_recurrence(n)
scatter( x, y, facecolor='none', edgecolor='blue', alpha=0.5 )
axes().set_aspect('equal')
savefig( 'additive_recurrence.png', dpi=200 )

Different values for s_{0} and \alpha produce different irregular meshes over the unit square.

Leave a Reply

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