1 2 3 ************************************************************** 4 * * 5 * prng 3.0 (release date: 2000/12/01) * 6 * * 7 * A library for the generation of pseudorandom numbers. * 8 * * 9 * * 10 * * 11 * (c) Otmar Lendl (lendl@cosy.sbg.ac.at) * 12 * * 13 ************************************************************** 14 15 16This package implements a collection of algorithms for generating 17pseudorandom numbers as a library of C functions. Please see the 18file INSTALL for installation instructions. A manual can be found 19in the doc directory. The licence has changed since version 2.2. 20It is now possible to choose either the licence terms in file 21LICENSE-2.2, or the GNU GPL as descripted in the file COPYING. 22 23The current version of this package can always be found on the pLab 24WWW server at http://random.mat.sbg.ac.at/ or at 25http://statistik.wu-wien.ac.at/prng/ of the 26ARVAG (Automatic Random VAriate Generation) project group. 27 28For problems please contact prng@statistik.wu-wien.ac.at 29(Otmar Lendl or Josef Leydold). 30 31 32FEATURES 33 34 o Portability. This library should compile on any computer with an 35 ANSI C compiler. A verification program is included. 36 37 o General Implementations. This library does not implement certain 38 fixed generators like RANDU or rand(), but implements the general 39 PRNG algorithms to which all parameters can be supplied by the user. 40 41 o Consistent and object-oriented interface. This interface simplifies 42 the PRNG handling inside the main application. 43 44 o Extensibility. New generators are easily integrated into the 45 framework of this library. 46 47 o Fully supported Pseudorandom number generating methods: 48 (free parametrization) 49 50 + LCG (linear congruential generator) 51 + ICG (inversive congruential generator) 52 + EICG (explicit inversive congruential generator) 53 + mEICG (modified explicit inversive congruential generator) 54 + DICG (digital inversive congruential generator) 55 + QCG (quadratic congruential generator) 56 + MT (Mersenne Twister by M. Matsumoto) 57 58 Fixed parameter PRNG (external generators): 59 60 + TT800 (a large TSFR by M. Matsumoto) 61 + CTG (Combined Tausworthe Generator by P. L'Ecuyer) 62 + MRG (Multiple Recursive Generator by P. L'Ecuyer) 63 + CMRG (Combined (Multiple Recursive Generator by P. L'Ecuyer) 64 65 plus the following methods (meta-generators): 66 67 + C (Compound generator) 68 + SUB (Subsequences) 69 + CON (Consecutive blocks) 70 + ANTI (Antithetic numbers, i.e. 1-U) 71 + AFILE (Ascii file) 72 + BFILE (Binary file) 73 74 75 76INTERFACE DESCRIPTION: 77---------------------- 78 79The interface has changed dramatically in version 2.0. As more and 80more generator types were added to this package, a new generic interface 81was needed. While still plain Ansi C, the architecture is now 82object-oriented. 83 84All generators are identified by a textual description. This description 85is either of the form "type(parameter1,parameter2, ...)" or is a 86shortcut name for a common PRNG as defined in prng_def.h. 87 88Calling prng_new() with such a description as the only argument will 89allocate a new generator object, initialize it, and return its handle 90(struct prng *). 91 92All further calls need this handle as the first argument. They are 93best explained by example: 94 95#include <prng.h> /* make sure that the compile can 96 find this file. */ 97 98struct prng *g; 99prng_num seed, n, M; 100double next, *array; 101int count; 102 103g = prng_new("eicg(2147483647,111,1,0"); 104 105printf("Short name: %s\n",prng_short_name(g)); 106 /* definition as in call to prng_new */ 107printf("Expanded name: %s\n",prng_long_name(g)); 108 /* Shortcuts expanded */ 109 110next = prng_get_next(g); /* get next number 0 <= next < 1 */ 111prng_get_array(g,array,count); /* fill array with count numbers */ 112prng_reset(g); /* reset the generator */ 113prng_free(g); /* deallocate the generator object */ 114 115These functions work with all generators. For certain generators, 116the following functions are available, too: 117 118if (prng_is_congruential(g)) 119 { 120 n = prng_get_next_int(g); /* return next *unscaled* number */ 121 M = prng_get_modulus(g); /* return the modulus of the prng */ 122 } 123 124if (prng_can_seed(g)) 125 prng_seed(g,seed); /* reseed the generator */ 126 127if (prng_can_fast_sub(g)) 128 puts(prng_get_sub_def(g,20,0); /* Get subsequence definition */ 129 130if (prng_can_fast_con(g)) 131 puts(prng_get_con_def(g,20,1); /* Get block definition */ 132 133 134*NOTE* 135 prng_new() performs only a rudimentary check on the parameters. 136 The user is responsible for enforcing all restrictions 137 on the parameters, such as checking that the modulus of an [E]ICG is 138 prime, or that LCG and ICG are maximum period generators. 139 140 Most of these functions are implemented as macros, so be 141 careful with autoincrements (++) in parameters. 142 143Prototypes: 144 145void prng_reset(struct prng *g) ; 146double prng_get_next(struct prng *g); 147void prng_get_array(struct prng *g, double *array,int count); 148void prng_free(struct prng *g); 149prng_num prng_get_next_int(struct prng *g); 150char * prng_short_name(struct prng *g); 151char * prng_long_name(struct prng *g); 152int prng_is_congruential(struct prng *g); 153prng_num prng_get_modulus(struct prng *g); 154int prng_can_seed(struct prng *g); 155void prng_seed(struct prng *g,prng_num next); 156int prng_can_fast_sub(struct prng *g); 157int prng_get_sub_def(struct prng *g, int s, int i); 158int prng_can_fast_con(struct prng *g); 159int prng_get_con_def(struct prng *g, int l, int i); 160 161 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 162 163 164EXAMPLES: 165--------- 166 167pairs.c is an example how to generate overlapping pairs of PRN using this 168package. 169 170tuples.c is a more general version of pairs. 171 172-- 173Otmar Lendl (lendl@cosy.sbg.ac.at) 1997/01/27 174