[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 2

rand_r Subroutine

Purpose

Generates pseudo-random numbers.

Libraries

Thread-Safe C Library (libc_r.a)

Berkeley Compatibility Library (libbsd.a)

Syntax

#include <stdlib.h>
int rand_r (Seed)
unsigned int *Seed;

Description

The rand_r subroutine generates and returns a pseudo-random number using a multiplicative congruential algorithm. The random-number generator has a period of 2**32, and it returns successive pseudo-random numbers.

Note: The rand_r subroutine is a simple random-number generator. Its spectral properties (the mathematical measurement of the randomness of a number sequence) are limited. See the drand48 subroutine or the random subroutine for more elaborate random-number generators that have greater spectral properties.

Parameter

Seed Specifies an initial seed value.

Return Values

0 Indicates that the subroutines was successful.
-1 Indicates that the subroutines was not successful.

Error Codes

If the following condition occurs, the rand_r subroutine sets the errno global variable to the corresponding value.

EINVAL The Seed parameter specifies a null value.

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

Programs using this subroutine must link to the libpthreads.a library.

File

/usr/include/sys/types.h Defines system macros, data types, and subroutines.

Related Information

The drand48, erand48_r, lrand48_r, nrand48_r, mrand48_r, jrand48_r, srand48_r, seed48_r, or lcong48_r subroutine, random, srandom_r, initstate_r, or setstate_r subroutine.

Subroutines Overview and List of Multithread Subroutines in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Contents | Glossary | Home | Search ]