Main Docs Examples Download Gallery

Random Number Generators

The ANL library includes a number of random number generators based on generators designed by George Marsaglia. The generators are:

LCG: Simple Linear Congruential Generator

Xorshift: Xor Shift generator

KISS: Keep It Simple, Stupid

MWC256: Multiply-with-carry 256

CMWC4096: Complementary-multiply-with-carry 4096


All of the random generators share a common interface:

class CBasePRNG
    virtual unsigned int get();
    virtual void setSeed(unsigned int s);
    void setSeedTime();
    unsigned int getTarget(unsigned int t);
    unsigned int getRange(unsigned int low, unsigned int high);
    double get01();

get(): Obtains a value in the range of (0,MAX_UNSIGNED_INT).

getTarget(): Obtains a value in the range of (0,target).

getRange(): Obtains a value in the range of (low,high).

get01(): Obtains a value in the range of (0,1).

setSeed(): Seeds the RNG.

setSeedTime(): Seeds the RNG from the system time.


#include "anl.h"
int main()
	anl.CMWC4096 rng;
	std::cout << rng.get() << std::endl;
	std::cout << rng.getTarget(1000) << std::endl;
	std::cout << rng.getRange(1,6) << std::endl;
	std::cout << rng.get01() << std::endl;
	return 1;
Expected output:

Random generators are used at various places throughout the noise library, to seed various values and transformations.

All content on page copyright 2011 Joshua Tippetts