rand, rand_r

Computes a sequence of pseudo-random integers in the range 0 to RAND_MAX (32767).

Library:LibC
Classification:ANSI
Service:General C Services

Syntax

  #include <stdlib.h> 
   
  int rand ( void );
  
  
  #include <stdlib.h> 
   
  int rand_r (
     unsigned long   *seed);
  

Parameters

seed

(IN/OUT) Points to a seed value (updated with each iteration).

Return Values

Returns the next pseudo-random number in the sequence.

Remarks

The rand_r function is the same as rand except that the caller passes storage for the seed, rather than relying on a global variable (which has the potential of being modified by subsequent calls to rand by other threads in the same NLM). The static data for the random number generator is stored for each thread.

The sequence of pseudo-random integers can be started at different values by calling the srand function.

See Also

sleep