Annotation of researchv10no/libc/gen/rand.c-1, revision 1.1.1.1

1.1       root        1: #define        LENG    17
                      2: static
                      3: long   ary[LENG] =
                      4: {
                      5:        0x4B14EA50L,
                      6:        0x53C4A8E0L,
                      7:        0x67B1FA98L,
                      8:        0x9CFB3BB5L,
                      9:        0x18761AF1L,
                     10:        0x7970CD66L,
                     11:        0xDBAFE136L,
                     12:        0x3C31FC3EL,
                     13:        0x697B37DEL,
                     14:        0x07BC568BL,
                     15:        0xCAFD3967L,
                     16:        0xA8F48722L,
                     17:        0x4AB26824L,
                     18:        0xA479EE47L,
                     19:        0x5C7246E2L,
                     20:        0x954BF297L,
                     21:        0x20A713ADL,
                     22: };
                     23: static
                     24: int    i1 = 0;
                     25: static
                     26: int    i2 = 12;
                     27: 
                     28: srand(seed)
                     29: {
                     30:        register i, j;
                     31: 
                     32:        for(i = 0; i < LENG; i++) {
                     33:                ary[i] = 0x55555555L;
                     34:                if(seed & 1)
                     35:                        ary[i] = 0xCCCCCCCCL;
                     36:                if(seed & 0x8000)
                     37:                        ary[i] ^= 0xF0F0F0F0L;
                     38:                seed >>= 1;
                     39:        }
                     40:        i1 = 0;
                     41:        i2 = 12;
                     42:        for(i = 1; i < 32; i += i)
                     43:        do {
                     44:                j = rand();
                     45:                ary[i1] += ary[i1] >> i;
                     46:                ary[i2] += ary[i2] << i;
                     47:        } while (i1);
                     48: }
                     49: 
                     50: rand()
                     51: {
                     52: 
                     53:        if(++i1 >= LENG)
                     54:                i1 = 0;
                     55:        if(++i2 >= LENG)
                     56:                i2 = 0;
                     57:        ary[i1] += ary[i2];
                     58:        return((ary[i1] >> 15) & 0x7FFF);
                     59: }
                     60: 
                     61: long
                     62: lrand()
                     63: {
                     64: 
                     65:        if(++i1 >= LENG)
                     66:                i1 = 0;
                     67:        if(++i2 >= LENG)
                     68:                i2 = 0;
                     69:        ary[i1] += ary[i2];
                     70:        return(ary[i1] & 0x7FFFFFFFL);
                     71: }
                     72: 
                     73: double
                     74: frand()
                     75: {
                     76: 
                     77:        if(++i1 >= LENG)
                     78:                i1 = 0;
                     79:        if(++i2 >= LENG)
                     80:                i2 = 0;
                     81:        ary[i1] += ary[i2];
                     82:        return((ary[i1] & 0x7FFFFFFFL) / 2.147483648e9);
                     83: }
                     84: 
                     85: nrand(n)
                     86: {
                     87: 
                     88:        if(++i1 >= LENG)
                     89:                i1 = 0;
                     90:        if(++i2 >= LENG)
                     91:                i2 = 0;
                     92:        ary[i1] += ary[i2];
                     93:        return((ary[i1] & 0x7FFFFFFFL) % n);
                     94: }

unix.superglobalmegacorp.com

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