·  Home
+   man pages
 -> Linux -> FreeBSD -> OpenBSD -> NetBSD -> Tru64 Unix -> HP-UX 11i -> IRIX
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

man pages->IRIX man pages -> ftn/rand (3)
 Title
 Content
 Arch
 Section All Sections 1 - General Commands 2 - System Calls 3 - Subroutines 4 - Special Files 5 - File Formats 6 - Games 7 - Macros and Conventions 8 - Maintenance Commands 9 - Kernel Interface n - New Commands

### 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.
```

```     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.

```     drand48(3C), random(3B)