Amiga Unix — 68040 · 68060

Manual pages › BSD C library (3B)

rand(3B)

simple random number generator

From the original Amiga UNIX 2.1 manual. Some things it mentions may not be in this release.

Also by this name: rand(3C), C library

NAME

rand, srand - simple random number generator

SYNOPSIS

cc [ flag... ] file ... -lucb
srand(seed)
int seed;
rand()

DESCRIPTION

rand uses a multiplicative congruential random number generator with period 2**32 to return successive pseudo-random numbers in the range from 0 to (2**31)-1. srand can be called at any time to reset the random-number generator to a random starting point. The generator is initially seeded with a value of 1.

SEE ALSO

random(3).  drand48(2), drand(3C),  rand(3C),  srand(3C)  in
the Programmer's Reference Manual.

NOTES

The spectral properties of rand leave a great deal to be desired. drand48(2) and random(3) provide much better, though more elaborate, random-number generators. The low bits of the numbers generated are not very random; use the middle bits. In particular the lowest bit alternates between 0 and 1.