|
Lines 1098-1113
Link Here
|
| 1098 |
static unsigned long rseed = 1; |
1098 |
static unsigned long rseed = 1; |
| 1099 |
static int last_random_value; |
1099 |
static int last_random_value; |
| 1100 |
|
1100 |
|
| 1101 |
/* A linear congruential random number generator based on the example |
1101 |
/* Use the random number genrator provided by the standard C library, |
| 1102 |
one in the ANSI C standard. This one isn't very good, but a more |
1102 |
else use a linear congruential random number generator based on the |
| 1103 |
complicated one is overkill. */ |
1103 |
ANSI C standard. This one isn't very good (the values are alternately |
|
|
1104 |
odd and even, for example), but a more complicated one is overkill. */ |
| 1104 |
|
1105 |
|
| 1105 |
/* Returns a pseudo-random number between 0 and 32767. */ |
1106 |
/* Returns a pseudo-random number between 0 and 32767. */ |
| 1106 |
static int |
1107 |
static int |
| 1107 |
brand () |
1108 |
brand () |
| 1108 |
{ |
1109 |
{ |
|
|
1110 |
#if defined(HAVE_RANDOM) |
| 1111 |
rseed = (unsigned int) (labs(random()) & 32767); |
| 1112 |
return rseed; |
| 1113 |
#else |
| 1109 |
rseed = rseed * 1103515245 + 12345; |
1114 |
rseed = rseed * 1103515245 + 12345; |
| 1110 |
return ((unsigned int)((rseed >> 16) & 32767)); /* was % 32768 */ |
1115 |
return ((unsigned int)((rseed >> 16) & 32767)); /* was % 32768 */ |
|
|
1116 |
#endif |
| 1111 |
} |
1117 |
} |
| 1112 |
|
1118 |
|
| 1113 |
/* Set the random number generator seed to SEED. */ |
1119 |
/* Set the random number generator seed to SEED. */ |
|
Lines 1115-1122
Link Here
|
| 1115 |
sbrand (seed) |
1121 |
sbrand (seed) |
| 1116 |
unsigned long seed; |
1122 |
unsigned long seed; |
| 1117 |
{ |
1123 |
{ |
|
|
1124 |
#if defined(HAVE_SRANDOM) |
| 1125 |
srandom(seed); |
| 1126 |
#else |
| 1118 |
rseed = seed; |
1127 |
rseed = seed; |
| 1119 |
last_random_value = 0; |
1128 |
last_random_value = 0; |
|
|
1129 |
#endif |
| 1120 |
} |
1130 |
} |
| 1121 |
|
1131 |
|
| 1122 |
static SHELL_VAR * |
1132 |
static SHELL_VAR * |