V8/usr/man/man3/rand.3
.TH RAND 3
.SH NAME
rand, lrand, frand, nrand, srand \- random number generator
.SH SYNOPSIS
.B int rand( )
.PP
.B long lrand( )
.PP
.B double frand( )
.PP
.B int nrand(val)
.br
.B int val;
.PP
.B srand(seed)
.br
.B int seed;
.PP
.SH DESCRIPTION
.I Rand
uses a polynominal feedback
random number generator with period
.if t 2\u\s749\s0\d\-2\u\s732\s0\d
.if n 2^49-2^32
to return successive uniform pseudo-random
numbers
.I x,
.if t .RI 0\(<= x <2\u\s715\s10\d.
.if n 0<=x<2^15.
.PP
.I Lrand
returns a uniform long
.I x,
.if t .RI 0\(<= x <2\u\s731\s10\d.
.if n 0<=x<2^31.
.PP
.I Frand
returns a uniform double
.I x,
.if t .RI 0.0\(<= x <1.0.
.if n 0.0<=x<1.0.
.PP
.I Nrand
returns a uniform integer
.I x,
.if t .RI 0\(<= x < val.
.if n 0<=x<val.
.PP
The generators are initialized by calling
.I srand
with whatever you like as argument.
To get a different starting value each time,
.IP
srand((int)time(0))
.LP
should work as long as it is not called more often
than once per second.
.SH BUGS
.I Rand
and
.I lrand
are quite machine-dependent.
In principle
.I frand
and
.I nrand
are more portable, but only the Eighth Edition has them.