home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name utrnd -- Random number generator
- *
- * Synopsis rnd = utrnd(pseed);
- *
- * float rnd The returned random value, in the
- * range from 0 to 1.
- * unsigned *pseed Pointer to a seed value. It is updated
- * on each successive call to UTRND.
- *
- * Description UTRND is a linear congruential pseudorandom number
- * generator. If the seed value is even, it uses the
- * system clock to find a seed; otherwise it uses the
- * passed value and then updates the seed on successive
- * calls. The value returned is the updated seed divided
- * by 65536.0.
- *
- * Returns rnd Random number between 0 and 1.
- * pseed Updated seed value
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <bquery.h>
-
- float utrnd(pseed)
- register unsigned *pseed;
- {
- int hours,minutes,seconds,hunds;
-
- if ((*pseed % 2) == 0)
- {
- qyrettim(&hours,&minutes,&seconds,&hunds);
- *pseed = (unsigned) (seconds * hunds);
- if ((*pseed % 2) == 0) /* Make sure the seed is odd */
- (*pseed)++; /* to ensure maximum period */
- }
- *pseed *= 15625; /* Multiplication modulo 65536 */
-
- return((float)(*pseed/65536.0));
- }