|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T r
Length: 777 (0x309)
Types: TextFile
Names: »rand.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Gb/rand.c.orig«
/*
** Galactic Bloodshed (Robert Chansky, smq@b)
** Random number generator
**
** float float_rand() this returns a random number between 0 and 1
**
** int int_rand(low,hi) - this returns an integer random number
** between hi and low, inclusive.
**
** int round_rand(float) - returns float rounded to integer, with
** proportional chance of rounding up or
** down.
**
** int rposneg() - either -1 or 1
*/
long random();
float float_rand()
{
return (-(float)random()/ 2147483648);
}
int int_rand(low,hi)
register int low,hi;
{
return( (hi<=low) ? low : (float_rand() * (hi - low + 1)) + low );
}
int round_rand(x)
register float x;
{
return ( (float_rand() > (x-(int)x)) ? (int)x : (int)(x+1) );
}
int rposneg()
{
return( (random()%1) ? -1 : 1 );
}