Mercurial > emacs
comparison src/fns.c @ 1743:a1933e20a2a3
(Frandom): Change arg name.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 08 Jan 1993 09:08:24 +0000 |
parents | 7381accd610d |
children | 04fb1d3d6992 |
comparison
equal
deleted
inserted
replaced
1742:69e337909652 | 1743:a1933e20a2a3 |
---|---|
47 "Return a pseudo-random number.\n\ | 47 "Return a pseudo-random number.\n\ |
48 On most systems all integers representable in Lisp are equally likely.\n\ | 48 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 } |
76 | 76 |
77 /* Random data-structure functions */ | 77 /* Random data-structure functions */ |