# include # include float fran ( float a, float b, int *seed ) // // Purpose: // // FRAN returns a scaled pseudorandom float between A and B. // // Parameters: // // Input, float A, B, the limits of the interval. // // Input/output, int *SEED, the "seed" value, which should NOT be 0. // On output, SEED has been updated. // // Output, float FRAN, a number between A and B. // { int i4_huge = 2147483647; int k; float value; // // Check SEED. // if ( *seed == 0 ) { printf ( "\n" ); printf ( "FRAN - Fatal error!\n" ); printf ( " Input value of SEED = 0.\n" ); exit ( 1 ); } // // Update SEED. // k = *seed / 127773; *seed = 16807 * ( *seed - k * 127773 ) - k * 2836; if ( *seed < 0 ) { *seed = *seed + i4_huge; } // // Convert SEED to a real number in [0,1]. // value = ( float ) ( *seed ) * 4.656612875E-10; // // Scale to a real number in [A,B]. // value = a + ( b - a ) * value; return value; }