Annotation of researchv10no/libc/gen/rand.c, 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:        register long slop = 0x7FFFFFFFL % n, v;
                     88: 
                     89:        do{
                     90:                if(++i1 >= LENG)
                     91:                        i1 = 0;
                     92:                if(++i2 >= LENG)
                     93:                        i2 = 0;
                     94:                ary[i1] += ary[i2];
                     95:                v = ary[i1] & 0x7FFFFFFFL;
                     96:        }while(v <= slop);
                     97:        return(v % n);
                     98: }
                     99: 
                    100: Srand(c1, c2, carray, clen)
                    101:        int *c1, *c2, *carray, *clen;
                    102: {
                    103:        register i, j;
                    104: 
                    105:        i = *c1; *c1 = i1; i1 = i;
                    106:        i = *c2; *c2 = i2; i2 = i;
                    107:        *clen = LENG;
                    108:        for(i = 0; i < LENG; i++)
                    109:        {
                    110:                j = carray[i]; carray[i] = ary[i]; ary[i] = j;
                    111:        }
                    112: }

unix.superglobalmegacorp.com

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