PostgreSQL Source Code  git master
erand48.c File Reference
#include "c.h"
#include <math.h>
Include dependency graph for erand48.c:

Go to the source code of this file.

Macros

#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)
 
long pg_jrand48 (unsigned short xseed[3])
 
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
 

Macro Definition Documentation

◆ RAND48_ADD

#define RAND48_ADD   (0x000b)

Definition at line 42 of file erand48.c.

Referenced by pg_srand48().

◆ RAND48_MULT_0

#define RAND48_MULT_0   (0xe66d)

Definition at line 39 of file erand48.c.

Referenced by pg_srand48().

◆ RAND48_MULT_1

#define RAND48_MULT_1   (0xdeec)

Definition at line 40 of file erand48.c.

Referenced by pg_srand48().

◆ RAND48_MULT_2

#define RAND48_MULT_2   (0x0005)

Definition at line 41 of file erand48.c.

Referenced by pg_srand48().

◆ RAND48_SEED_0

#define RAND48_SEED_0   (0x330e)

Definition at line 36 of file erand48.c.

Referenced by pg_srand48().

◆ RAND48_SEED_1

#define RAND48_SEED_1   (0xabcd)

Definition at line 37 of file erand48.c.

◆ RAND48_SEED_2

#define RAND48_SEED_2   (0x1234)

Definition at line 38 of file erand48.c.

Function Documentation

◆ _dorand48()

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(), pg_jrand48(), and pg_lrand48().

59 {
60  unsigned long accu;
61  unsigned short temp[2];
62 
63  accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
64  (unsigned long) _rand48_add;
65  temp[0] = (unsigned short) accu; /* lower 16 bits */
66  accu >>= sizeof(unsigned short) * 8;
67  accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
68  (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
69  temp[1] = (unsigned short) accu; /* middle 16 bits */
70  accu >>= sizeof(unsigned short) * 8;
71  accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
72  xseed[0] = temp[0];
73  xseed[1] = temp[1];
74  xseed[2] = (unsigned short) accu;
75 }
static unsigned short _rand48_mult[3]
Definition: erand48.c:49
static unsigned short _rand48_add
Definition: erand48.c:54

◆ pg_erand48()

double pg_erand48 ( unsigned short  xseed[3])

Definition at line 79 of file erand48.c.

References _dorand48().

Referenced by doLog(), geqo_rand(), getExponentialRand(), getGaussianRand(), getPoissonRand(), getrand(), and sampler_random_fract().

80 {
81  _dorand48(xseed);
82  return ldexp((double) xseed[0], -48) +
83  ldexp((double) xseed[1], -32) +
84  ldexp((double) xseed[2], -16);
85 }
static void _dorand48(unsigned short xseed[3])
Definition: erand48.c:58

◆ pg_jrand48()

long pg_jrand48 ( unsigned short  xseed[3])

Definition at line 95 of file erand48.c.

References _dorand48().

Referenced by pg_backend_random(), pg_frontend_random(), and RandomCancelKey().

96 {
97  _dorand48(xseed);
98  return ((long) xseed[2] << 16) + ((long) xseed[1]);
99 }
static void _dorand48(unsigned short xseed[3])
Definition: erand48.c:58

◆ pg_lrand48()

long pg_lrand48 ( void  )

Definition at line 88 of file erand48.c.

References _dorand48(), and _rand48_seed.

Referenced by random().

89 {
91  return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1);
92 }
static unsigned short _rand48_seed[3]
Definition: erand48.c:44
static void _dorand48(unsigned short xseed[3])
Definition: erand48.c:58

◆ pg_srand48()

void pg_srand48 ( long  seed)

Definition at line 102 of file erand48.c.

References _rand48_add, _rand48_mult, _rand48_seed, RAND48_ADD, RAND48_MULT_0, RAND48_MULT_1, RAND48_MULT_2, and RAND48_SEED_0.

Referenced by srandom().

103 {
105  _rand48_seed[1] = (unsigned short) seed;
106  _rand48_seed[2] = (unsigned short) (seed >> 16);
111 }
static unsigned short _rand48_seed[3]
Definition: erand48.c:44
#define RAND48_SEED_0
Definition: erand48.c:36
#define RAND48_ADD
Definition: erand48.c:42
static unsigned short _rand48_mult[3]
Definition: erand48.c:49
static unsigned short _rand48_add
Definition: erand48.c:54
#define RAND48_MULT_1
Definition: erand48.c:40
#define RAND48_MULT_2
Definition: erand48.c:41
#define RAND48_MULT_0
Definition: erand48.c:39

Variable Documentation

◆ _rand48_add

unsigned short _rand48_add = RAND48_ADD
static

Definition at line 54 of file erand48.c.

Referenced by _dorand48(), and pg_srand48().

◆ _rand48_mult

unsigned short _rand48_mult[3]
static
Initial value:
= {
}
#define RAND48_MULT_1
Definition: erand48.c:40
#define RAND48_MULT_2
Definition: erand48.c:41
#define RAND48_MULT_0
Definition: erand48.c:39

Definition at line 49 of file erand48.c.

Referenced by _dorand48(), and pg_srand48().

◆ _rand48_seed

unsigned short _rand48_seed[3]
static
Initial value:
= {
}
#define RAND48_SEED_0
Definition: erand48.c:36
#define RAND48_SEED_2
Definition: erand48.c:38
#define RAND48_SEED_1
Definition: erand48.c:37

Definition at line 44 of file erand48.c.

Referenced by pg_lrand48(), and pg_srand48().