*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> ftn/rand (3)              
Title
Content
Arch
Section
 

Contents


RAND(3F)							      RAND(3F)


NAME    [Toc]    [Back]

     rand, irand, srand	- random number	generator

SYNOPSIS    [Toc]    [Back]

     integer iseed, i, irand
     double precision x, rand

     call srand(iseed)

     i = irand(	)

     x = rand( )

DESCRIPTION    [Toc]    [Back]

     Irand generates successive	pseudo-random integers in the range from 0 to
     2**15-1.  rand generates pseudo-random numbers distributed	in [0, 1.0].
     Srand uses	its integer argument to	re-initialize the seed for successive
     invocations of irand and rand.

SEE ALSO    [Toc]    [Back]

      
      
     rand(3C).
rand(3C)							      rand(3C)


NAME    [Toc]    [Back]

     rand, srand, rand_r - simple random-number	generator

SYNOPSIS    [Toc]    [Back]

     #include <stdlib.h>

     int rand (void);

     int rand_r	(unsigned int *seed);

     void srand	(unsigned int seed);

DESCRIPTION    [Toc]    [Back]

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

     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.

     rand_r is a reentrant version of rand.  If	rand_r is called with the same
     initial value for *seed and the value of *seed is not changed between
     successive	returns	and calls to rand_r, the same sequence shall be
     generated.	 This function is useful when multiple threads in a process
     each wish to get their own	repeatable pseudo-random number	sequence.  The
     feature test macro	_SGI_REENTRANT_FUNCTIONS should	be defined to make
     this function visible.

NOTES    [Toc]    [Back]

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

     In	a multi-threaded program rand is made MP safe by single-threading
     access to the shared seed.	 For best performance threaded applications
     should use	rand_r instead.

SEE ALSO    [Toc]    [Back]

      
      
     drand48(3C), random(3B)


									PPPPaaaaggggeeee 1111
[ Back ]
 Similar pages
Name OS Title
srand FreeBSD bad random number generator
random Linux random number generator.
rand_r OpenBSD bad random number generator
srand OpenBSD bad random number generator
rand_r NetBSD bad random number generator
rand OpenBSD bad random number generator
rand FreeBSD bad random number generator
rand NetBSD bad random number generator
sranddev FreeBSD bad random number generator
rand_r FreeBSD bad random number generator
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service