comparison src/fns.c @ 12008:637671248a31

(Frandom): Use EMACS_INT, not int. Use NULL, not 0, as arg of `time'.
author Karl Heuer <kwzh@gnu.org>
date Tue, 30 May 1995 03:15:27 +0000
parents d8227796a997
children 9d84af59f868
comparison
equal deleted inserted replaced
12007:4179378fa410 12008:637671248a31
58 With positive integer argument N, return random number in interval [0,N).\n\ 58 With positive integer argument N, return random number in interval [0,N).\n\
59 With argument t, set the random number seed from the current time and pid.") 59 With argument t, set the random number seed from the current time and pid.")
60 (limit) 60 (limit)
61 Lisp_Object limit; 61 Lisp_Object limit;
62 { 62 {
63 int val; 63 EMACS_INT val;
64 Lisp_Object lispy_val;
64 unsigned long denominator; 65 unsigned long denominator;
65 66
66 if (EQ (limit, Qt)) 67 if (EQ (limit, Qt))
67 seed_random (getpid () + time (0)); 68 seed_random (getpid () + time (NULL));
68 if (NATNUMP (limit) && XFASTINT (limit) != 0) 69 if (NATNUMP (limit) && XFASTINT (limit) != 0)
69 { 70 {
70 /* Try to take our random number from the higher bits of VAL, 71 /* Try to take our random number from the higher bits of VAL,
71 not the lower, since (says Gentzel) the low bits of `random' 72 not the lower, since (says Gentzel) the low bits of `random'
72 are less random than the higher ones. We do this by using the 73 are less random than the higher ones. We do this by using the
79 val = get_random () / denominator; 80 val = get_random () / denominator;
80 while (val >= XFASTINT (limit)); 81 while (val >= XFASTINT (limit));
81 } 82 }
82 else 83 else
83 val = get_random (); 84 val = get_random ();
84 return make_number (val); 85 XSETINT (lispy_val, val);
86 return lispy_val;
85 } 87 }
86 88
87 /* Random data-structure functions */ 89 /* Random data-structure functions */
88 90
89 DEFUN ("length", Flength, Slength, 1, 1, 0, 91 DEFUN ("length", Flength, Slength, 1, 1, 0,