Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
13d62fad
Commit
13d62fad
authored
Nov 06, 2008
by
Juanma Barranquero
Browse files
* fns.c (Frandom): Rename arg N to LIMIT to match the docs; doc fix.
parent
6edf847b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
src/ChangeLog
src/ChangeLog
+4
-0
src/fns.c
src/fns.c
+9
-8
No files found.
src/ChangeLog
View file @
13d62fad
2008-11-06 Juanma Barranquero <lekktu@gmail.com>
* fns.c (Frandom): Rename arg N to LIMIT to match the docs; doc fix.
2008-11-06 Glenn Morris <rgm@gnu.org>
* xterm.c (handle_one_xevent): Don't let popup menus cause
...
...
src/fns.c
View file @
13d62fad
...
...
@@ -95,18 +95,19 @@ DEFUN ("random", Frandom, Srandom, 0, 1, 0,
doc
:
/* Return a pseudo-random number.
All integers representable in Lisp are equally likely.
On most systems, this is 29 bits' worth.
With positive integer argument N, return random number in interval [0,N).
With argument t, set the random number seed from the current time and pid. */
)
(
n
)
Lisp_Object
n
;
With positive integer LIMIT, return random number in interval [0,LIMIT).
With argument t, set the random number seed from the current time and pid.
Other values of LIMIT are ignored. */
)
(
limit
)
Lisp_Object
limit
;
{
EMACS_INT
val
;
Lisp_Object
lispy_val
;
unsigned
long
denominator
;
if
(
EQ
(
n
,
Qt
))
if
(
EQ
(
limit
,
Qt
))
seed_random
(
getpid
()
+
time
(
NULL
));
if
(
NATNUMP
(
n
)
&&
XFASTINT
(
n
)
!=
0
)
if
(
NATNUMP
(
limit
)
&&
XFASTINT
(
limit
)
!=
0
)
{
/* Try to take our random number from the higher bits of VAL,
not the lower, since (says Gentzel) the low bits of `random'
...
...
@@ -115,10 +116,10 @@ With argument t, set the random number seed from the current time and pid. */)
it's possible to get a quotient larger than n; discarding
these values eliminates the bias that would otherwise appear
when using a large n. */
denominator
=
((
unsigned
long
)
1
<<
VALBITS
)
/
XFASTINT
(
n
);
denominator
=
((
unsigned
long
)
1
<<
VALBITS
)
/
XFASTINT
(
limit
);
do
val
=
get_random
()
/
denominator
;
while
(
val
>=
XFASTINT
(
n
));
while
(
val
>=
XFASTINT
(
limit
));
}
else
val
=
get_random
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment