#include /* Global */ int SEED_x,SEED_y,SEED_z; /* ------------------------------- RANDOM NUMBER GENERATOR ------------------------------- This random number generator has a cycle of about 7.6e12. You can call it many times without reseeding. Seed it manually by calling Seed or Clock_Seed. Clock_Seed reads the biosclock and thus works only on DOS systems. The random number returned from Random lies between 0.0 and 1.0. The seed values for the x,y, and z portions of the generator are held externally. k.t. kilty */ void Seed(int x,int y,int z) { SEED_x=x; SEED_y=y; SEED_z=z; } /* seeding random number gen */ void Clock_Seed(void) { long time,shift; time=biostime(0,0); shift=time/1000; shift=time-1000*shift; SEED_x=(int)shift; SEED_y=(int)shift-1; SEED_z=(int)shift-2; } /* Clock_Seed */ float Random(void) { /* returns a random number between 0.0 and 1.0 the generator cycle is 7.6e12 roughly and the generator needs SEED_x,SEED_y and SEED_z to be kept in Global. They provide a random reseeding on each call.*/ int x_new,y_new,z_new; float output; x_new=171*(SEED_x%177) - 2*(SEED_x/177); if (x_new<0) x_new+=30269; y_new=173*(SEED_y%177) - 2*(SEED_y/177); if (y_new<0) y_new+=30773; z_new=177*(SEED_z%185) - 2*(SEED_z/185); if (z_new<0) z_new+=32749; output = (float)x_new/30269.0 + (float)y_new/30773.0 + (float)z_new/32749.0; output -= (int)output; SEED_x=x_new; SEED_y=y_new; SEED_z=z_new; return(output); } /* random */