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_MULT   UINT64CONST(0x0005deece66d)
 
#define RAND48_ADD   UINT64CONST(0x000b)
 
#define RAND48_SEED_0   (0x330e)
 
#define RAND48_SEED_1   (0xabcd)
 
#define RAND48_SEED_2   (0x1234)
 

Functions

static uint64 _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]
 

Macro Definition Documentation

◆ RAND48_ADD

#define RAND48_ADD   UINT64CONST(0x000b)

Definition at line 42 of file erand48.c.

Referenced by _dorand48().

◆ RAND48_MULT

#define RAND48_MULT   UINT64CONST(0x0005deece66d)

Definition at line 41 of file erand48.c.

Referenced by _dorand48().

◆ RAND48_SEED_0

#define RAND48_SEED_0   (0x330e)

Definition at line 45 of file erand48.c.

Referenced by pg_srand48().

◆ RAND48_SEED_1

#define RAND48_SEED_1   (0xabcd)

Definition at line 46 of file erand48.c.

◆ RAND48_SEED_2

#define RAND48_SEED_2   (0x1234)

Definition at line 47 of file erand48.c.

Function Documentation

◆ _dorand48()

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

Definition at line 63 of file erand48.c.

References RAND48_ADD, and RAND48_MULT.

Referenced by pg_erand48(), pg_jrand48(), and pg_lrand48().

64 {
65  /*
66  * We do the arithmetic in uint64; any type wider than 48 bits would work.
67  */
68  uint64 in;
69  uint64 out;
70 
71  in = (uint64) xseed[2] << 32 | (uint64) xseed[1] << 16 | (uint64) xseed[0];
72 
73  out = in * RAND48_MULT + RAND48_ADD;
74 
75  xseed[0] = out & 0xFFFF;
76  xseed[1] = (out >> 16) & 0xFFFF;
77  xseed[2] = (out >> 32) & 0xFFFF;
78 
79  return out;
80 }
#define RAND48_ADD
Definition: erand48.c:42
#define RAND48_MULT
Definition: erand48.c:41

◆ pg_erand48()

double pg_erand48 ( unsigned short  xseed[3])

Definition at line 88 of file erand48.c.

References _dorand48().

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

89 {
90  uint64 x = _dorand48(xseed);
91 
92  return ldexp((double) (x & UINT64CONST(0xFFFFFFFFFFFF)), -48);
93 }
static uint64 _dorand48(unsigned short xseed[3])
Definition: erand48.c:63

◆ pg_jrand48()

long pg_jrand48 ( unsigned short  xseed[3])

Definition at line 112 of file erand48.c.

References _dorand48().

Referenced by initRandomState(), and main().

113 {
114  uint64 x = _dorand48(xseed);
115 
116  return (int32) ((x >> 16) & UINT64CONST(0xFFFFFFFF));
117 }
signed int int32
Definition: c.h:346
static uint64 _dorand48(unsigned short xseed[3])
Definition: erand48.c:63

◆ pg_lrand48()

long pg_lrand48 ( void  )

Definition at line 100 of file erand48.c.

References _dorand48(), and _rand48_seed.

Referenced by random(), test_huge_distances(), and test_pattern().

101 {
102  uint64 x = _dorand48(_rand48_seed);
103 
104  return (x >> 17) & UINT64CONST(0x7FFFFFFF);
105 }
static unsigned short _rand48_seed[3]
Definition: erand48.c:49
static uint64 _dorand48(unsigned short xseed[3])
Definition: erand48.c:63

◆ pg_srand48()

void pg_srand48 ( long  seed)

Definition at line 131 of file erand48.c.

References _rand48_seed, and RAND48_SEED_0.

Referenced by srandom().

132 {
134  _rand48_seed[1] = (unsigned short) seed;
135  _rand48_seed[2] = (unsigned short) (seed >> 16);
136 }
static unsigned short _rand48_seed[3]
Definition: erand48.c:49
#define RAND48_SEED_0
Definition: erand48.c:45

Variable Documentation

◆ _rand48_seed

unsigned short _rand48_seed[3]
static
Initial value:
= {
}
#define RAND48_SEED_0
Definition: erand48.c:45
#define RAND48_SEED_2
Definition: erand48.c:47
#define RAND48_SEED_1
Definition: erand48.c:46

Definition at line 49 of file erand48.c.

Referenced by pg_lrand48(), and pg_srand48().