/* This is the random number generator proposed by George Marsaglia in Florida State University Report: FSU-SCRI-87-50 */ double RandomUniform(void) { double uni; /* Make sure the initialisation routine has been called */ if (!test) RandomInitialise(1802,9373); uni = u[i97-1] - u[j97-1]; if (uni <= 0.0) uni++; u[i97-1] = uni; i97--; if (i97 == 0) i97 = 97; j97--; if (j97 == 0) j97 = 97; c -= cd; if (c < 0.0) c += cm; uni -= c; if (uni < 0.0) uni++; return(uni); }
void init_rand(parameter *paras) { int ij = -1, kl = -1; char file[10]; strcpy(file, "seed"); if(paras->rSeed == 1) r_seed(&ij, &kl, file); else { srand(time(NULL)); while(ij < 0 || ij > 31328 || kl < 0 || kl > 30081) { ij = (int)((double)rand() / RAND_MAX * 31328); kl = (int)((double)rand() / RAND_MAX * 30081); } w_seed(ij, kl, file); } RandomInitialise(ij, kl); return; }
double slave_psgold(double shift, double scale, int seed, int stream) { int i; double currgcv, bestgcv, bestlambda = 0; struct SP_1D * best_sp; best_sp = spline_1d_copy(sp_psgold); RandomInitialise(stream, stream+1, seed); lambda_psgold = exp(RandomDouble(MIN_LOG_LAMBDA_PSGOLD, MAX_LOG_LAMBDA_PSGOLD)); bestgcv = INFINITY; sp_1d_set_knots(sp_psgold, 0., 1.); sp_1d_set_knots(best_sp, 0., 1.); for (i = 0; i < NUMBER_LOOPS_PSGOLD; i++) { currgcv = lambda_loop_psgold(shift, scale); if (currgcv < bestgcv) { bestlambda = lambda_psgold; bestgcv = currgcv; } currgcv = knot_loop_psgold(shift, scale); if (currgcv < bestgcv) { free_SP_1D(best_sp); best_sp = spline_1d_copy(sp_psgold); bestgcv = currgcv; } } return bestlambda; }
void initialize_rand() /* Iniciando el generador de aleatorios randomlib.h */ { unsigned int i, j; srand((unsigned int)time((time_t *)NULL)); i = (unsigned int) (31329.0 * rand() / (RAND_MAX + 1.0)); j = (unsigned int) (30082.0 * rand() / (RAND_MAX + 1.0)); RandomInitialise(i,j); }