mrand48

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

Format

#include  <stdlib.h>

long int mrand48  (void);

Description

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

It returns signed long integers uniformly distributed over the range of y values such that -231

Before you call the mrand48 function, use either srand48, seed48, or lcong48 to initialize the random number generator. You must initialize the mrand48 function prior to invoking it, 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 values returned by the mrand48 function is computed by first generating the next 48-bit Xi in the sequence. Then the appropriate bits, according to the type of returned data item, are copied from the high-order (most significant) bits of Xi and transformed into the returned value.

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

Return Values
Returns signed long integers uniformly distributed over the range -231


Previous Page | Next Page | Table of Contents | Index