Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ drand48(3) — OSF/1 1.0 (TIN) MIPS

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

rand(3)

rand(3)

random(3)

drand48(3)  —  Subroutines

OSF

NAME

drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48 − Generates uniformly distributed pseudo-random number sequences

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <stdlib.h>
double drand48 ( void );
double erand48 (
    unsigned short xsubi[3] );
long jrand48 (
    unsigned short xsubi[3] );
void lcong48 (
    unsigned short param[7] );
long lrand48  ( void );
long mrand48  ( void );
long nrand48 (
    unsigned short xsubi[3] );
unsigned short ∗seed48 (
    unsigned short seed_16v[3] );
void srand48 (
    long seed_val);

PARAMETERS

xsubiSpecifies an array of three shorts, which, when concatenated together, form a 48-bit integer. 

seed_valSpecifies the initialization value to begin randomization. Changing this value changes the randomization pattern. 

seed_16vSpecifies another seed value; an array of three unsigned shorts that form a 48-bit seed value. 

paramSpecifies an array specifying the initialXi, the multiplier value a, and the addend value c. 

DESCRIPTION

This family of functions generates pseudo-random numbers using the linear congruential algorithm and 48-bit integer arithmetic. 

The drand48() and erand48() functions return nonnegative, double-precision, floating-point values uniformly distributed over the range of y values such that 0 ≤ y < 1.0. 

The lrand48() and nrand48() functions return nonnegative long integers uniformly distributed over the range of y values such that 0 ≤ y < 231. 

The mrand48() and jrand48() functions return signed long integers uniformly distributed over the range of y values such that -231 ≤ y < 231. 

The srand48(), seed48(), and lcong48() functions initialize the random-number generator.  Programs should invoke one of them before calling the drand48(), lrand48(), or the mrand48() functions.  (Although it is not recommended practice, constant default initializer values are supplied automatically if the drand48(), lrand48(), or mrand48() functions are called without first calling an initialization function.) The erand48(), nrand48(), and jrand48() functions do not require that an initialization function be called first. 

All the functions work 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 parameter m equals248; hence 48-bit integer arithmetic is performed.  Unless lcong48() has been invoked, the multiplier valuea and the addend valuec are given by a = 5DEECE66D 16 = 273673163155 8
c = B 16 = 13 8

The values returned by the drand48(), erand48(), lrand48(), nrand48(), mrand48(), and jrand48() functions are computed by first generating the next 48-bitXi in the sequence. Then the appropriate number of bits, according to the type of data item to be returned, are copied from the high-order (most significant) bits ofXi and transformed into the returned value. 

The drand48(), lrand48(), and mrand48() functions store the last 48-bitXi generated into an internal buffer, which is why they must be initialized prior to being invoked. 

The erand48(), nrand48(), and jrand48() functions require that the calling program provide storage for the successiveXi values in the array pointed to by the xsubi parameter.  This is why these routines do not have to be initialized; the calling program merely has to place the desired initial value ofXi into the array and pass it as a parameter. 

By using different parameters, the erand48(), nrand48(), and jrand48() functions allow separate modules of a large program to generate several independent sequences of pseudo-random numbers, that is, the sequence of numbers that one module generates does not depend upon how many times the functions are called by other modules. 

The initializer function srand48() sets the high-order 32 bits ofXi to the LONG_BIT bits contained in its parameter.  The low order 16 bits ofXi are set to the arbitrary value 330E16.

The initializer function seed48() sets the value of Xi to the 48-bit value specified in the array pointed to by the seed_16v parameter. In addition, seed48() returns a pointer to a 48-bit internal buffer that contains the previous value ofXi that is used only by seed48(). The returned pointer allows you to restart the pseudo-random sequence at a given point. Use the pointer to copy the previousXi value into a temporary array.  To resume where the original sequence left off, you can call seed48() with a pointer to this array. 

The lcong48() function specifies the initialXi value, the multiplier value a, and the addend value c.  The param array elements param[0-2] specify Xi, param[3-5] specify the multiplier a, and param[6] specifies the 16-bit addend c.  After lcong48() has been called, a subsequent call to either srand48() or seed48() restores the standard a and c as specified previously. 

NOTES

AES Support Level:
Trial use

RETURN VALUES

The drand48() and erand48() functions return nonnegative, double-precision, floating-point values.  The lrand48() and nrand48() functions return signed long integers uniformly distributed over the range 0 ≤ y < 231.  The mrand48() and jrand48() functions return signed long integers uniformly distributed over the range -231 ≤ y < 231. 

The seed48() function returns a pointer to a 48-bit internal buffer. 

The lcong48() and srand48() functions do not return a value. 

RELATED INFORMATION

Functions: rand(3), rand(3), random(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026