aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1995-01-19 23:36:43 +0000
committerKarl Heuer1995-01-19 23:36:43 +0000
commit99175c23d34107a2d4d7b1eb00d40b4c0d6704a3 (patch)
treef2dd0bcbb5439a6889445347bb89d248aecffc8f /src
parent66263a7d6e5026f71e679353ee81e33f7a0e9244 (diff)
downloademacs-99175c23d34107a2d4d7b1eb00d40b4c0d6704a3.tar.gz
emacs-99175c23d34107a2d4d7b1eb00d40b4c0d6704a3.zip
(Frandom): Call seed_random and get_random.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/fns.c b/src/fns.c
index 71c7243d706..c17c62020a6 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -47,23 +47,24 @@ DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0,
47 return arg; 47 return arg;
48} 48}
49 49
50extern long get_random ();
51extern void seed_random ();
52extern long time ();
53
50DEFUN ("random", Frandom, Srandom, 0, 1, 0, 54DEFUN ("random", Frandom, Srandom, 0, 1, 0,
51 "Return a pseudo-random number.\n\ 55 "Return a pseudo-random number.\n\
52All integers representable in Lisp are equally likely.\n\ 56All integers representable in Lisp are equally likely.\n\
53 On most systems, this is 28 bits' worth.\n\ 57 On most systems, this is 28 bits' worth.\n\
54With argument N, return random number in interval [0,N).\n\ 58With positive integer argument N, return random number in interval [0,N).\n\
55With argument t, set the random number seed from the current time and pid.") 59With argument t, set the random number seed from the current time and pid.")
56 (limit) 60 (limit)
57 Lisp_Object limit; 61 Lisp_Object limit;
58{ 62{
59 int val; 63 int val;
60 unsigned long denominator; 64 unsigned long denominator;
61 extern long random ();
62 extern srandom ();
63 extern long time ();
64 65
65 if (EQ (limit, Qt)) 66 if (EQ (limit, Qt))
66 srandom (getpid () + time (0)); 67 seed_random (getpid () + time (0));
67 if (NATNUMP (limit) && XFASTINT (limit) != 0) 68 if (NATNUMP (limit) && XFASTINT (limit) != 0)
68 { 69 {
69 /* Try to take our random number from the higher bits of VAL, 70 /* Try to take our random number from the higher bits of VAL,
@@ -75,11 +76,11 @@ With argument t, set the random number seed from the current time and pid.")
75 when using a large limit. */ 76 when using a large limit. */
76 denominator = ((unsigned long)1 << VALBITS) / XFASTINT (limit); 77 denominator = ((unsigned long)1 << VALBITS) / XFASTINT (limit);
77 do 78 do
78 val = (random () & (((unsigned long)1 << VALBITS) - 1)) / denominator; 79 val = get_random () / denominator;
79 while (val >= XFASTINT (limit)); 80 while (val >= XFASTINT (limit));
80 } 81 }
81 else 82 else
82 val = random (); 83 val = get_random ();
83 return make_number (val); 84 return make_number (val);
84} 85}
85 86