lrand48

Generates uniformly distributed pseudorandom number sequences. Returns 48-bit signed long integers.

Format

#include  <stdlib.h>

long int lrand48  (void);

Description

This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic.

It returns nonnegative, long integers uniformly distributed over the range of y values such that 0

Before you call the lrand48 function use either srand48, seed48, or lcong48 to initialize the random number generator. You must initialize prior to invoking the lrand48 function, because it stores the last 48-bit Xi generated into an internal buffer. (Although it is not recommended, constant default initializer values are supplied automatically if the drand48, lrand48, or mrand48 functions are called without first calling an initialization function.)

The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula:

       Xn+1 = (aXn+c)mod m        n >= 0

The argument m equals 248 , so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are:

      a = 5DEECE66D16 = 2736731631558

      c = B16 = 138

The value returned by the lrand48 function is computed by first generating the next 48-bit Xi in the sequence. Then the appropriate bits, according to the type of data item to be returned, are copied from the high-order (most significant) bits of Xi and transformed into the returned value.

See also drand48, lcong48, mrand48, seed48, and srand48 in this section.

Return Values
Signed nonnegative long integers uniformly distributed over the range 0


Previous Page | Next Page | Table of Contents | Index