Function: random
random is a function defined in fns.c.
Signature
(random &optional LIMIT)
Documentation
Return a pseudo-random integer.
By default, return a random fixnum value with all fixnums equally likely. With positive integer value of the optional argument LIMIT, return random integer in interval [0,LIMIT); it is an error to pass a negative LIMIT. If LIMIT is t, set the random number seed from the system's entropy pool if available, otherwise from less-random volatile data such as the time. If LIMIT is a string, set the seed based on the string's contents. Any other value of LIMIT is interpreted as nil.
See Info node (elisp)Random Numbers for more details.
Other relevant functions are documented in the number group.
Probably introduced at or before Emacs version 17.
Shortdoc
;; number
(random 6)
=> 1
Source Code
// Defined in /usr/src/emacs/src/fns.c
{
if (EQ (limit, Qt))
init_random ();
else if (STRINGP (limit))
seed_random (SSDATA (limit), SBYTES (limit));
else if (FIXNUMP (limit))
{
EMACS_INT lim = XFIXNUM (limit);
if (lim <= 0)
xsignal1 (Qargs_out_of_range, limit);
return get_random_fixnum (lim);
}
else if (BIGNUMP (limit))
{
struct Lisp_Bignum *lim = XBIGNUM (limit);
if (mpz_sgn (*bignum_val (lim)) <= 0)
xsignal1 (Qargs_out_of_range, limit);
return get_random_bignum (lim);
}
return make_ufixnum (get_random ());
}