#ifndef _rngs_h #define _rngs_h #include /* * -------------------------------------------------------------------------- * This is a Turbo Pascal unit for random number generation. The use of this * unit is recommended as a replacement for the Turbo Pascal function Random * and procedure Randomize - particularly in simulation applications where * the statistical 'goodness' of the random number generator is important. * * The generator upon which this unit is based is a so-called 'Lehmer random * number generator' which returns a pseudo-random real number uniformly * distributed between 0.0 and 1.0. The period is (m - 1) where * m = 2,147,483,647 and the smallest and largest possible values are (1 / m) * and 1 - (1 / m) respectively. For more details see - * * "Random Number Generators: Good Ones Are Hard To Find" * Steve Park & Keith Miller * Communications of the ACM, October, 1988 * * This unit actually supplies 256 different "streams" of random numbers. * The procedure Select_Stream can be used to switch between streams. * * Note that a math co-processor is assumed. To use this unit without a math * co-processor, change all instances of 'double' to 'real' and change the * compiler directive from $N+ to $N-. * * Note that as of 1-08-91 the multiplier used in this unit has been changed * from the previous "minimal standard" 16807 to a new value of 48271. To * use this unit in its old (16807) form change the constants 'a', 'check' * and 'a256' as indicated in the implementation section comments. * * -------------------------------------------------------------------------- * Author : Steve Park * Language : Turbo Pascal, 5.0 * Latest Revision : 2-19-92 * Reference : Lecture Notes on Simulation, by Steve Park * -------------------------------------------------------------------------- * C Translation By : Tracey A. Beauchat * -------------------------------------------------------------------------- */ void initialize(void); /* * This function should be called before calling any other function * in the RNGS library. It initializes the streams with default * values. * */ double Random(void); /* * Random is a Lehmer generator which returns a pseudo-random real number * uniformly distributed between 0.0 and 1.0. The period is (m - 1) * where m = 2,147,483,647 and the smallest and largest possible values * are (1 / m) and 1 - (1 / m) respectively. * */ void Select_Stream(int stream); /* * Use this (optional) procedure to define the currently selected stream * i.e. that stream from which the next random number will come. * */ void Randomize(long int x); /* * Use this (optional) procedure to initialize all of the 256 random * number streams according to the following conventions: * * if x > 0 then - x is, in fact, the initial seed * if x = 0 then - the initial seed is to be supplied interactively * if x < 0 then - the initial seed is obtained from the DOS clock * */ void Get_Seed(long int *x); /* * Use this (optional) procedure to get the current value of the random * number generator seed for the currently selected stream. * */ void Put_Seed(long int x); #endif /* _rngs_h */