Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ rand(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

drand48(S)


 rand(S)                        6 January 1993                        rand(S)


 Name

    rand, srand - simple random-number generator

 Syntax


    cc ... -lc


    #include  <stdlib.h>

    int rand ()

    void srand (seed)
    unsigned seed;


 Description

    The rand function uses a multiplicative congruential random-number gen-
    erator with period 2^32 that returns successive pseudo-random numbers in
    the range from 0 to (2^15)-1.

    The srand function 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.

 Notes

    The spectral properties of rand are limited.  The drand48(S) function
    provides a much better, though more elaborate, random-number generator.

    The following functions define the semantics of the functions rand and
    srand.

       static unsigned long int next = 1;
       int rand()
       {
            next = next * 1103515245 + 12345;
            return ((unsigned int)(next/65536) % 32768);
       }
       void srand(seed)
       unsigned int seed;
       {
            next = seed;
       }


    Specifying the semantics makes it possible to reproduce the behavior of
    programs that use pseudo-random sequences.  This facilitates the testing
    of portable applications in different implementations.

 See also

    drand48(S)

 Standards conformance

    rand and srand are conformant with:
    AT&T SVID Issue 2;
    X/Open Portability Guide, Issue 3, 1989;
    ANSI X3.159-1989 Programming Language -- C;
    IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C
    Language] (ISO/IEC 9945-1);
    and NIST FIPS 151-1.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026