home *** CD-ROM | disk | FTP | other *** search
- /*
- * rand.c
- * contains: gfsrand(),gfrand(),nfrom()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- */
-
- #include <stdio.h>
- #include "gfuncts.h"
-
- static long rnum;
-
- /*
- * void
- * gfsrand(x)
- *
- * ARGUMENT
- * (short) x - value to initialize rnum with.
- *
- * DESCRIPTION
- * This function sets variable rnum with the parameter to gfsrand()
- */
- void GF_CONV gfsrand(num)
- short num;
- {
- rnum=(long)num;
- }
-
- /*
- * short
- * gfrand(void)
- *
- * DESCRIPTION
- * Generates pseudorandom number of period 2^32 on the interval 0..32768
- *
- * RETURNS
- * pseudorandom integer between 0 an 32768
- */
- short GF_CONV gfrand()
- {
- rnum=rnum*0x41C64E6DL+0x00003039L;
- return((short)(rnum>>16)&0x7FFF);
- }
-
- /*
- * short
- * nfrom(lo,hi)
- *
- * ARGUMENT
- * (short) lo - lower limit
- * (short) hi - upper limit
- *
- * DESCRIPTION
- * generates pseudorandom integer between the limits specified.
- *
- * RETURNS
- * pseudorandom integer between the limits specified.
- */
- short GF_CONV nfrom(lo,hi)
- register short lo,hi;
- {
- register short nb=hi-lo+1;
- return(gfrand()%nb+lo);
- }
-