diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 12 |
1 files changed, 6 insertions, 6 deletions
| @@ -49,27 +49,27 @@ On most systems all integers representable in Lisp are equally likely.\n\ | |||
| 49 | This is 24 bits' worth.\n\ | 49 | This is 24 bits' worth.\n\ |
| 50 | With argument N, return random number in interval [0,N).\n\ | 50 | With argument N, return random number in interval [0,N).\n\ |
| 51 | With argument t, set the random number seed from the current time and pid.") | 51 | With argument t, set the random number seed from the current time and pid.") |
| 52 | (arg) | 52 | (limit) |
| 53 | Lisp_Object arg; | 53 | Lisp_Object limit; |
| 54 | { | 54 | { |
| 55 | int val; | 55 | int val; |
| 56 | extern long random (); | 56 | extern long random (); |
| 57 | extern srandom (); | 57 | extern srandom (); |
| 58 | extern long time (); | 58 | extern long time (); |
| 59 | 59 | ||
| 60 | if (EQ (arg, Qt)) | 60 | if (EQ (limit, Qt)) |
| 61 | srandom (getpid () + time (0)); | 61 | srandom (getpid () + time (0)); |
| 62 | val = random (); | 62 | val = random (); |
| 63 | if (XTYPE (arg) == Lisp_Int && XINT (arg) != 0) | 63 | if (XTYPE (limit) == Lisp_Int && XINT (limit) != 0) |
| 64 | { | 64 | { |
| 65 | /* Try to take our random number from the higher bits of VAL, | 65 | /* Try to take our random number from the higher bits of VAL, |
| 66 | not the lower, since (says Gentzel) the low bits of `random' | 66 | not the lower, since (says Gentzel) the low bits of `random' |
| 67 | are less random than the higher ones. */ | 67 | are less random than the higher ones. */ |
| 68 | val &= 0xfffffff; /* Ensure positive. */ | 68 | val &= 0xfffffff; /* Ensure positive. */ |
| 69 | val >>= 5; | 69 | val >>= 5; |
| 70 | if (XINT (arg) < 10000) | 70 | if (XINT (limit) < 10000) |
| 71 | val >>= 6; | 71 | val >>= 6; |
| 72 | val %= XINT (arg); | 72 | val %= XINT (limit); |
| 73 | } | 73 | } |
| 74 | return make_number (val); | 74 | return make_number (val); |
| 75 | } | 75 | } |