Prev: Transcendental Functions Up: Numbers
In a computer, a series of pseudo-random numbers is generated in a
deterministic fashion. The numbers are not truly random, but they have
certain properties that mimic a random series. For example, all
possible values occur equally often in a pseudo-random series.
In Emacs, pseudo-random numbers are generated from a "seed" number.
Starting from any given seed, the `random' function always generates
the same sequence of numbers. Emacs always starts with the same seed
value, so the sequence of values of `random' is actually the same in
each Emacs run! For example, in one operating system, the first call
to `(random)' after you start Emacs always returns -1457731, and the
second one always returns -7692030. This is helpful for debugging.
If you want truly unpredictable random numbers, execute `(random
t)'. This chooses a new seed based on the current time of day and on
Emacs' process ID number.
- Function: random &optional LIMIT
This function returns a pseudo-random integer. When called more
than once, it returns a series of pseudo-random integers.
If LIMIT is `nil', then the value may in principle be any integer.
If LIMIT is a positive integer, the value is chosen to be
nonnegative and less than LIMIT (only in Emacs 19).
If LIMIT is `t', it means to choose a new seed based on the
current time of day and on Emacs's process ID number.
On some machines, any integer representable in Lisp may be the
result of `random'. On other machines, the result can never be
larger than a certain maximum or less than a certain (negative)
automatically generated by info2www