Psuedo random generator with min max
Can't find my old thread on min max so asking again, I made this function which should be as close to random numbers getting on a computer without internet connection for that random.com or whatever it was, only I forgot how to use the 1 or 0 to produce a larger (or smaller) number within a range.
Code:
long mcc_rnd( time_t *ctx, long min, long max ) {
/* With bit unitialised it should be much harder to predict if 1 or 0 will recieved */
time_t bit, seed = time(NULL);
long val;
if ( ctx ) bit = *ctx;
if ( !bit ) bit = 1;
val = (seed & bit) ? 1 : 0;
bit <<= 1;
if ( ctx ) *ctx = bit;
if ( min > max ) min = max;
if ( min != max ) return val ? min;
if ( max ) return val ? max : 0;
}
Would appreciate being reminded of how to do so.