Mercurial > emacs
comparison src/fns.c @ 8901:ab65a3dae221
(Frandom): Fix Lisp_Object vs. int problems.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Mon, 19 Sep 1994 00:15:08 +0000 |
parents | e0c0247dca19 |
children | cafc16f356c2 |
comparison
equal
deleted
inserted
replaced
8900:3c6b5ba4d559 | 8901:ab65a3dae221 |
---|---|
29 #include "commands.h" | 29 #include "commands.h" |
30 | 30 |
31 #include "buffer.h" | 31 #include "buffer.h" |
32 #include "keyboard.h" | 32 #include "keyboard.h" |
33 #include "intervals.h" | 33 #include "intervals.h" |
34 | |
35 extern Lisp_Object Flookup_key (); | |
34 | 36 |
35 Lisp_Object Qstring_lessp, Qprovide, Qrequire; | 37 Lisp_Object Qstring_lessp, Qprovide, Qrequire; |
36 Lisp_Object Qyes_or_no_p_history; | 38 Lisp_Object Qyes_or_no_p_history; |
37 | 39 |
38 static Lisp_Object internal_equal (); | 40 static Lisp_Object internal_equal (); |
62 | 64 |
63 if (EQ (limit, Qt)) | 65 if (EQ (limit, Qt)) |
64 srandom (getpid () + time (0)); | 66 srandom (getpid () + time (0)); |
65 if (XTYPE (limit) == Lisp_Int && XINT (limit) > 0) | 67 if (XTYPE (limit) == Lisp_Int && XINT (limit) > 0) |
66 { | 68 { |
67 if (XINT (limit) >= 0x40000000) | 69 if (XFASTINT (limit) >= 0x40000000) |
68 /* This case may occur on 64-bit machines. */ | 70 /* This case may occur on 64-bit machines. */ |
69 val = random () % XINT (limit); | 71 val = random () % XFASTINT (limit); |
70 else | 72 else |
71 { | 73 { |
72 /* Try to take our random number from the higher bits of VAL, | 74 /* Try to take our random number from the higher bits of VAL, |
73 not the lower, since (says Gentzel) the low bits of `random' | 75 not the lower, since (says Gentzel) the low bits of `random' |
74 are less random than the higher ones. We do this by using the | 76 are less random than the higher ones. We do this by using the |
77 these values eliminates the bias that would otherwise appear | 79 these values eliminates the bias that would otherwise appear |
78 when using a large limit. */ | 80 when using a large limit. */ |
79 denominator = (unsigned long)0x40000000 / XFASTINT (limit); | 81 denominator = (unsigned long)0x40000000 / XFASTINT (limit); |
80 do | 82 do |
81 val = (random () & 0x3fffffff) / denominator; | 83 val = (random () & 0x3fffffff) / denominator; |
82 while (val >= limit); | 84 while (val >= XFASTINT (limit)); |
83 } | 85 } |
84 } | 86 } |
85 else | 87 else |
86 val = random (); | 88 val = random (); |
87 return make_number (val); | 89 return make_number (val); |