らんすうはっせいき


r(n)= (r(n-1)*a + b) mod c
n番目の乱数は、前の乱数に等しく、aを乗じ、bを加え、
mod c
a= 7^5
b= 0
c= (2^31) - 1
20億個の乱数が発生し、約350秒かかります
平均して毎秒、約600万個の乱数を発生することができます.


/*
for rnd1(), rnd2(), irnd(), init_rnd()
  */
// ----------------------------------------------

#include "inc01.h"
// ----------------------------------------------

void main()
{
	// r(n)= (r(n-1)*a + b) mod c
	double a,b,c, x1,x2,x3, dt, ct1;
	int s1, s2, t1;

	a= pow(7, 5);
	b= 0;
	c= (pow(2, 31)) - 1;

	skip(1);
	printf("a= %.3lf, b= %.3lf, c= %.3lf
", a, b, c); // ---------------------------------------------- time1(&t1); s1= t1; s2= s1; ct1= 0; do { // get a new s1 x1= (double) s1; x2= x1*a + b; x3= fmod(x2, c); s1= (int) (x3 + 0.5); ct1++; } while (s1 != s2); // ---------------------------------------------- time2(t1, &dt); skip(1); printf("ct1= %.0lf, dt= %10.4lf
", ct1, dt); }// end of main()