[ThinAir Home] [Table of Contents] [Introduction] [Characteristics of Random Number Sequences]

2 Quick Start

The ThinAir library contains more than 40 random number generators. This section lists a half-dozen good generators and how to call them from your program. If you want to know some of the tradeoffs of different generators or more advanced ways of using them, you'll need to read beyond this section.

The simplest way to use this library is to pick a generator and use the rand() interface to access it. You can accomplish this using a few simple steps.

  1. Include the ThinAir rand_rng.h header file in any file where you use rand(), random(), randomize(), srand(), or MAX_RAND.
  2. At the beginning of your code, call the function setup_rand() with a heap-based your chosen generator as the argument.
  3. Use the functions rand(), random(), randomize(), and srand() as described in the C++ standard library documentation.

Here are six examples of the correct use of this function. Each of these generators take an optional seed argument when they are constructed.

setup_rand( new Knuth27RandGen() );      // found in erndmcnm.h
setup_rand( new BoroshNiederreiterRandGen() ); // found in erndmcon.h
setup_rand( new WatermanRandGen() ); // found in erndmcon.h
setup_rand( new LavauxJanssensRandGen() ); // found in erndmcon.h
setup_rand( new MarsagliaMCRandGen() ); // found in erndmcon.h
setup_rand( new Knuth28RandGen() ); // found in erndsecm.h

Unlike the standard rand() function that returns short ints, the ThinAir rand() function returns long ints. If you use the random( limit ) function instead of rand(), you will not notice any difference. For an example and further information on this interface, see Section 5.2.


For further information, contact G. Wade Johnson (gwadej@anomaly.org).

© 1997 G. Wade Johnson. All rights reserved.
http://www.anomaly.org/ThinAir/quikstrt.html