// See jims1Rand.h
//
// This implements a pseudoRandom number generator
// Rand(i+1) = a * Rand(i) + c mod m
// based on the discussion in Numberical Recipes chapter 7.
#include "jims1Rand.h"
// I chose these numbers at random. (No pun intended.)
// All three are prime, which may help spread out the values.
int m1 = 12237;
int a1 = 10007;
int c1 = 443;
// The last random returned, and the number used to
// calculate the next.
int jims1Seed;
// like the system call srand()
void jims1Srand(unsigned int seed){
jims1Seed = seed % m1;
}
// like the system call rand()
int jims1Rand(){
jims1Seed = ( a1 * jims1Seed + c1 ) % m1;
return jims1Seed;
}
// like system constant RAND_MAX
int jims1GetRAND_MAX(){
return m1;
}
syntax highlighted by Code2HTML, v. 0.9.1