Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

reentrant(3)

drand48(3C)



rand(3C)                       DG/UX R4.11MU05                      rand(3C)


NAME
       rand, rand_r, srand - simple random-number generator

SYNOPSIS
       #include <stdlib.h>

       int rand (void);

       int rand_r (unsigned int *seed);

       void srand (unsigned int seed);

DESCRIPTION
       rand 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 rand function uses a static variable
       for the seed value which is overwritten with each call to the
       function.  The rand_r function allows you to specify the seed value
       as a non-static variable.  If the function rand_r is called with the
       same seed value, the sequence of pseudo-random numbers will be
       repeated.

       The function srand uses the argument seed as a seed for a new
       sequence of pseudo-random numbers to be returned by subsequent calls
       to the function rand.  If the function srand is then called with the
       same seed value, the sequence of pseudo-random numbers will be
       repeated.  If the function rand is called before any calls to srand
       have been made, the same sequence will be generated as when srand is
       first called with a seed value of 1.


   Considerations for Threads Programming
                     +---------+-----------------------------+
                     |         |                      async- |
                     |function | reentrant   cancel   cancel |
                     |         |             point     safe  |
                     +---------+-----------------------------+
                     |rand     |     N         -        -    |
                     |rand_r   |     Y         N        N    |
                     |srand    |     Y         N        N    |
                     +---------+-----------------------------+

NOTES
       The function rand_r is only available in the shared library, libc.so.

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

SEE ALSO
       reentrant(3), drand48(3C).


Licensed material--property of copyright holder(s)

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