srand man page on SmartOS

Man page or keyword search:  
man Server   16655 pages
apropos Keyword Search (all sections)
Output format
SmartOS logo
[printable version]

RAND(3C)							      RAND(3C)

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

SYNOPSIS
       #include <stdlib.h>

       int rand(void);

       void srand(unsigned int seed);

       int rand_r(unsigned int *seed);

DESCRIPTION
       The  rand()  function  uses a multiplicative congruential random-number
       generator with period 2^32 that returns successive  pseudo-random  num‐
       bers in the range of 0 to RAND_MAX (defined in <stdlib.h>).

       The   srand()  function	uses  the  argument  seed  as a seed for a new
       sequence of pseudo-random numbers to be returned by subsequent calls to
       rand().	If  srand()  is	 then  called  with  the  same seed value, the
       sequence of pseudo-random numbers  will	be  repeated.	If  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.

       The  rand_r() function has the same functionality as rand() except that
       a pointer to a seed  seed must be supplied by the caller.  If  rand_r()
       is called with the same initial value for the object pointed to by seed
       and that object is not modified between successive calls	 to  rand_r(),
       the  same  sequence  as that produced by calls to rand() will be gener‐
       ated.

       The rand() and  srand()	functions  provide  per-process	 pseudo-random
       streams	shared	by all threads. The same effect can be achieved if all
       threads call rand_r() with a pointer  to	 the  same  seed  object.  The
       rand_r()	 function  allows a thread to generate a private pseudo-random
       stream by having the seed object be private to the thread.

USAGE
       The spectral properties of rand() are limited.  The  drand48(3C)	 func‐
       tion provides a better, more elaborate random-number generator.

       When compiling multithreaded applications, the  _REENTRANT flag must be
       defined on the compile line.  This flag should be used only  in	multi‐
       threaded applications.

ATTRIBUTES
       See attributes(5) for descriptions of the following attributes:

       ┌────────────────────┬─────────────────┐
       │  ATTRIBUTE TYPE    │ ATTRIBUTE VALUE │
       ├────────────────────┼─────────────────┤
       │Interface Stability │ Standard	      │
       ├────────────────────┼─────────────────┤
       │MT-Level	    │ Safe	      │
       └────────────────────┴─────────────────┘

SEE ALSO
       drand48(3C), attributes(5), standards(5)

				 May 19, 2004			      RAND(3C)
[top]

List of man pages available for SmartOS

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net