Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions | Variables

erand48.c File Reference

#include "c.h"
#include <math.h>
Include dependency graph for erand48.c:

Go to the source code of this file.

Defines

#define RAND48_SEED_0   (0x330e)
#define RAND48_SEED_1   (0xabcd)
#define RAND48_SEED_2   (0x1234)
#define RAND48_MULT_0   (0xe66d)
#define RAND48_MULT_1   (0xdeec)
#define RAND48_MULT_2   (0x0005)
#define RAND48_ADD   (0x000b)

Functions

static void _dorand48 (unsigned short xseed[3])
double pg_erand48 (unsigned short xseed[3])
long pg_lrand48 (void)
void pg_srand48 (long seed)

Variables

static unsigned short _rand48_seed [3]
static unsigned short _rand48_mult [3]
static unsigned short _rand48_add = RAND48_ADD

Define Documentation

#define RAND48_ADD   (0x000b)

Definition at line 42 of file erand48.c.

#define RAND48_MULT_0   (0xe66d)

Definition at line 39 of file erand48.c.

#define RAND48_MULT_1   (0xdeec)

Definition at line 40 of file erand48.c.

#define RAND48_MULT_2   (0x0005)

Definition at line 41 of file erand48.c.

#define RAND48_SEED_0   (0x330e)

Definition at line 36 of file erand48.c.

#define RAND48_SEED_1   (0xabcd)

Definition at line 37 of file erand48.c.

#define RAND48_SEED_2   (0x1234)

Definition at line 38 of file erand48.c.


Function Documentation

static void _dorand48 ( unsigned short  xseed[3]  )  [static]

Definition at line 58 of file erand48.c.

References _rand48_add, and _rand48_mult.

Referenced by pg_erand48(), and pg_lrand48().

{
    unsigned long accu;
    unsigned short temp[2];

    accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
        (unsigned long) _rand48_add;
    temp[0] = (unsigned short) accu;    /* lower 16 bits */
    accu >>= sizeof(unsigned short) * 8;
    accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
        (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
    temp[1] = (unsigned short) accu;    /* middle 16 bits */
    accu >>= sizeof(unsigned short) * 8;
    accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
    xseed[0] = temp[0];
    xseed[1] = temp[1];
    xseed[2] = (unsigned short) accu;
}

double pg_erand48 ( unsigned short  xseed[3]  ) 

Definition at line 79 of file erand48.c.

References _dorand48().

Referenced by doCustom(), geqo_rand(), and getrand().

{
    _dorand48(xseed);
    return ldexp((double) xseed[0], -48) +
        ldexp((double) xseed[1], -32) +
        ldexp((double) xseed[2], -16);
}

long pg_lrand48 ( void   ) 

Definition at line 88 of file erand48.c.

References _dorand48(), and _rand48_seed.

Referenced by random().

{
    _dorand48(_rand48_seed);
    return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1);
}

void pg_srand48 ( long  seed  ) 

Definition at line 95 of file erand48.c.

References _rand48_add, _rand48_mult, and _rand48_seed.

Referenced by srandom().

{
    _rand48_seed[0] = RAND48_SEED_0;
    _rand48_seed[1] = (unsigned short) seed;
    _rand48_seed[2] = (unsigned short) (seed >> 16);
    _rand48_mult[0] = RAND48_MULT_0;
    _rand48_mult[1] = RAND48_MULT_1;
    _rand48_mult[2] = RAND48_MULT_2;
    _rand48_add = RAND48_ADD;
}


Variable Documentation

unsigned short _rand48_add = RAND48_ADD [static]

Definition at line 54 of file erand48.c.

Referenced by _dorand48(), and pg_srand48().

unsigned short _rand48_mult[3] [static]
Initial value:
 {
    RAND48_MULT_0,
    RAND48_MULT_1,
    RAND48_MULT_2
}

Definition at line 49 of file erand48.c.

Referenced by _dorand48(), and pg_srand48().

unsigned short _rand48_seed[3] [static]
Initial value:
 {
    RAND48_SEED_0,
    RAND48_SEED_1,
    RAND48_SEED_2
}

Definition at line 44 of file erand48.c.

Referenced by pg_lrand48(), and pg_srand48().