Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ rand(S) — OpenDesktop Software Development System 1.0.0d

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     RAND(S)                   UNIX System V                   RAND(S)



     Name
          rand, srand - simple random-number generator

     Syntax
          int rand ( )

          void srand (seed)
          unsigned seed;

     Description
          The rand function uses a multiplicative congruential
          random-number generator 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.

     See Also
          drand48(S)

     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.

     Standards Conformance
          rand and srand are conformant with:
          AT&T SVID Issue 2, Select Code 307-127;
          The X/Open Portability Guide II of January 1987;
          ANSI  X3.159-198X  C  Language  Draft  Standard,   May   13,
          1988;
          IEEE  POSIX  Std  1003.1-1988  with  C  Standard   Language-
          Dependent System Support;
          and NIST FIPS 151-1.

                                             (printed 6/20/89)



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