Annotation of coherent/a/usr/src/misc/randl.c, revision 1.1.1.1

1.1       root        1: /* fake version of ldiv() */
                      2: typedef struct ldiv_t { long quot, rem; } ldiv_t;
                      3: ldiv_t ldiv(numer, denom) long numer, denom;
                      4: {
                      5:        ldiv_t l;
                      6:        l.quot = numer / denom;
                      7:        l.rem = numer % denom;
                      8:        return l;
                      9: }
                     10: /*-----------------------------------------------------------------*/
                     11: /* Efficient and Portable Combined Random Number Generators */
                     12: /* Pierre L'Ecuyer */
                     13: /* CACM V. 31 N. 6 pp. 742-749, 774, June 1988 */
                     14: 
                     15: /* This random number generator has a period of 2e18. */
                     16: /* It can be computed with 2 divides and 4 multiplies */
                     17: /* where divides return 16 bit quotient and remainder */
                     18: /* of a 32 bit number divided by a 16 bit number, and */
                     19: /* mulitplies return a 32 bit product of two 16 bit */
                     20: /* factors.  The ANSI portable implementation is less than */
                     21: /* optimal, since it must be implemented using long arithmetic, */
                     22: /* but at least the algorithm can be specified. */
                     23: 
                     24: static long s1 = 1;
                     25: static long s2 = 1;
                     26: 
                     27: void srandl(seed1, seed2) unsigned long seed1, seed2;
                     28: {
                     29:        s1 = seed1 % 2147483562L + 1;
                     30:        s2 = seed2 % 2147483398L + 1;
                     31: }
                     32: 
                     33: /* uniform distribution in [1 .. 2147483562] */
                     34: long randl()
                     35: {
                     36:        ldiv_t l;
                     37:        register long t;
                     38: 
                     39:        l = ldiv(s1, 53668L);
                     40:        if ((s1 = 40014L * l.rem - 12211 * l.quot) < 0)
                     41:                s1 += 2147483563L;
                     42:        l = ldiv(s2, 52774L);
                     43:        if ((s2 = 40692L * l.rem - 3791 * l.quot) < 0)
                     44:                s2 += 2147483399L;
                     45:        if ((t = s1 - s2) < 1)
                     46:                t += 2147483562L;
                     47:        return t-1;
                     48: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.