# 2.11BSD#431 - /usr/src/games/rogue/random.c

##### Functions

    coin_toss         X
    get_rand          X
    rand_percent      X
    rrandom           X
    srrandom          X

       1: #ifndef lint
       2: static char sccsid[] = "@(#)random.c	5.1 (Berkeley) 11/25/87";
       3: #endif /* not lint */
       4:
       5: static long rntb[32] = {
       6:              3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342,
       7:     0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x7449e56b,
       8:     0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f,
       9:     0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d,
      10:     0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
      11:     0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e,
      12:     0x8999220b, 0x27fb47b9
      13: };
      14:
      15: static long *fptr = &rntb[4];
      16: static long *rptr = &rntb[1];
      17: static long *state = &rntb[1];
      18: static int rand_type = 3;
      19: static int rand_deg = 31;
      20: static int rand_sep = 3;
      21: static long *end_ptr = &rntb[32];
      22:
      23: srrandom(x)
      24: int x;
      25: {
      26:     register int i;
      27:     long rrandom();
      28:
      29:     state[0] = (long) x;
      30:     if (rand_type != 0) {
      31:         for (i = 1; i < rand_deg; i++) {
      32:             state[i] = 1103515245 * state[i - 1] + 12345;
      33:         }
      34:         fptr = &state[rand_sep];
      35:         rptr = &state[0];
      36:         for (i = 0; i < 10 * rand_deg; i++) {
      37:             (void) rrandom();
      38:         }
      39:     }
      40: }
      41:
      42: long
      43: rrandom()
      44: {
      45:     long i;
      46:
      47:     if (rand_type == 0) {
      48:         i = state[0] = (state[0]*1103515245 + 12345) & 0x7fffffff;
      49:     } else {
      50:         *fptr += *rptr;
      51:         i = (*fptr >> 1) & 0x7fffffff;
      52:         if (++fptr >= end_ptr) {
      53:             fptr = state;
      54:             ++rptr;
      55:         } else {
      56:             if (++rptr >= end_ptr) {
      57:                 rptr = state;
      58:             }
      59:         }
      60:     }
      61:     return(i);
      62: }
      63:
      64: get_rand(x, y)
      65: register int x, y;
      66: {
      67:     register int r, t;
      68:     long lr;
      69:
      70:     if (x > y) {
      71:         t = y;
      72:         y = x;
      73:         x = t;
      74:     }
      75:     lr = rrandom();
      76:     lr &= (long) 0x00003fff;
      77:     r = (int) lr;
      78:     r = (r % ((y - x) + 1)) + x;
      79:     return(r);
      80: }
      81:
      82: rand_percent(percentage)
      83: register int percentage;
      84: {
      85:     return(get_rand(1, 100) <= percentage);
      86: }
      87:
      88: coin_toss()
      89: {
      90:
      91:     return(((rrandom() & 01) ? 1 : 0));
      92: }

#### Defined functions

coin_toss defined in line 88; used 11 times

- in /usr/src/games/rogue/level.c line 467, 526
- in /usr/src/games/rogue/monster.c line 101, 708
- in /usr/src/games/rogue/move.c line 367
- in /usr/src/games/rogue/object.c line 133, 480
- in /usr/src/games/rogue/ring.c line 207
- in /usr/src/games/rogue/spec_hit.c line 413, 448
- in /usr/src/games/rogue/use.c line 186

get_rand defined in line 64; used 110 times

- in line 85
- in /usr/src/games/rogue/hit.c line 155, 416
- in /usr/src/games/rogue/init.c line 130
- in /usr/src/games/rogue/inventory.c line 381-382(2), 395-399(2), 580, 591
- in /usr/src/games/rogue/level.c line 70, 219-230(8), 351, 359, 384, 399, 432, 443-449(3), 487-488(2), 609-610(2), 680-681(2), 810, 840-841(2)
- in /usr/src/games/rogue/monster.c line 97, 118, 199-201(2), 335, 379-380(2), 550, 673, 759
- in /usr/src/games/rogue/move.c line 359, 480
- in /usr/src/games/rogue/object.c line 133(2), 162-164(2), 185, 350, 375, 413, 458-463(3), 469-470(2), 520, 528-529(2), 543-544(2)
- in /usr/src/games/rogue/ring.c line 177, 203
- in /usr/src/games/rogue/room.c line 217-218(2), 235, 250, 256-258(2), 389
- in /usr/src/games/rogue/spec_hit.c line 96, 120, 157, 215, 381, 400
- in /usr/src/games/rogue/throw.c line 238-241(2)
- in /usr/src/games/rogue/trap.c line 78, 118-137(9)
- in /usr/src/games/rogue/use.c line 80, 100, 124-129(2), 379, 387, 466, 506, 523, 551, 560
- in /usr/src/games/rogue/zap.c line 140, 247, 307, 321, 340, 354

rand_percent defined in line 82; used 41 times

- in /usr/src/games/rogue/hit.c line 51, 102
- in /usr/src/games/rogue/level.c line 104-107(2), 238, 299, 367, 410, 441, 605
- in /usr/src/games/rogue/monster.c line 270, 531, 709, 733-736(2)
- in /usr/src/games/rogue/move.c line 62, 362
- in /usr/src/games/rogue/object.c line 134, 160, 553, 611-612(2)
- in /usr/src/games/rogue/spec_hit.c line 31, 84, 100, 116, 139, 217, 365, 378, 397, 429-433(2)
- in /usr/src/games/rogue/throw.c line 111
- in /usr/src/games/rogue/trap.c line 67, 90, 225
- in /usr/src/games/rogue/use.c line 378
- in /usr/src/games/rogue/zap.c line 295, 318, 335

rrandom defined in line 42; used 5 times

- in line 27, 37, 75, 91
- in /usr/src/games/rogue/rogue.h line 427

srrandom defined in line 23; used 1 times

- in /usr/src/games/rogue/init.c line 74

#### Defined variables

end_ptr defined in line 21; used 2 times

- in line 52-56(2)

fptr defined in line 15; used 5 times

- in line 34, 50-53(4)

rand_deg defined in line 19; used 2 times

- in line 31-36(2)

rand_sep defined in line 20; used 1 times

- in line 34

rand_type defined in line 18; used 2 times

- in line 30, 47

rntb defined in line 5; used 4 times

- in line 15-21(4)

rptr defined in line 16; used 5 times

- in line 35, 50-57(4)

sccsid defined in line 2; never used
state defined in line 17; used 9 times

- in line 29-35(5), 48-57(4)

Last modified: 1987-11-26 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 874 |