initstate() — Initialize generator for random()

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <stdlib.h>

char *initstate(unsigned seed, char *state, size_t size);

General description

The initstate() function allows a state array, pointed to by the state argument, to be initialized for future use in calls to the random() functions by the calling thread. The size argument, which specifies the size in bytes of the state array, is used by the initstate() function to decide how sophisticated a random-number generator to use; the larger the state array, the more random the numbers. Values for the amount of state information are 8, 32, 64, 128, and 256 bytes. While other amounts are rounded down to the nearest known value. The seed argument specifies a starting point for the random-number sequence and provides for restarting at the same point. The initstate() function returns a pointer to the previous state information array.

Returned value

If successful, initstate() returns a pointer to the previous state array.

If unsuccessful, initstate() returns a NULL pointer.If initstate() is called with size less than 8, it will return NULL.

Related information