PostgreSQL Source Code: src/backend/utils/adt/pseudorandomfuncs.c File Reference (original) (raw)
#include "[postgres.h](postgres%5F8h%5Fsource.html)"#include <math.h>#include "[common/pg_prng.h](pg%5F%5Fprng%5F8h%5Fsource.html)"#include "[miscadmin.h](miscadmin%5F8h%5Fsource.html)"#include "[utils/date.h](date%5F8h%5Fsource.html)"#include "utils/fmgrprotos.h"#include "[utils/numeric.h](numeric%5F8h%5Fsource.html)"#include "[utils/timestamp.h](utils%5F2timestamp%5F8h%5Fsource.html)"

Go to the source code of this file.
◆ CHECK_RANGE_BOUNDS
| #define CHECK_RANGE_BOUNDS | ( | | rmin, | | ---------------------------- | - | | ----- | | | rmax | | | | | ) | | | |
Value:
do { \
if ((rmin) > (rmax)) \
errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
errmsg("lower bound must be less than or equal to upper bound")); \
} while (0)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
Definition at line 33 of file pseudorandomfuncs.c.
◆ date_random()
Definition at line 203 of file pseudorandomfuncs.c.
204{
208
210
213 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
214 errmsg("lower and upper bounds must be finite"));
215
217
219
221}
#define PG_RETURN_DATEADT(x)
#define DATE_IS_NOBEGIN(j)
#define PG_GETARG_DATEADT(n)
#define ereport(elevel,...)
int64 pg_prng_int64_range(pg_prng_state *state, int64 rmin, int64 rmax)
static void initialize_prng(void)
static pg_prng_state prng_state
#define CHECK_RANGE_BOUNDS(rmin, rmax)
References CHECK_RANGE_BOUNDS, DATE_IS_NOBEGIN, DATE_IS_NOEND, ereport, errcode(), errmsg(), ERROR, initialize_prng(), PG_GETARG_DATEADT, pg_prng_int64_range(), PG_RETURN_DATEADT, and prng_state.
◆ drandom()
◆ drandom_normal()
◆ initialize_prng()
| static void initialize_prng ( void ) | static |
|---|
Definition at line 47 of file pseudorandomfuncs.c.
48{
50 {
51
52
53
54
55
57 {
60
61
64 }
66 }
67}
TimestampTz GetCurrentTimestamp(void)
Datum now(PG_FUNCTION_ARGS)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
#define pg_prng_strong_seed(state)
static bool prng_seed_set
References GetCurrentTimestamp(), MyProcPid, now(), pg_prng_seed(), pg_prng_strong_seed, prng_seed_set, prng_state, and unlikely.
Referenced by date_random(), drandom(), drandom_normal(), int4random(), int8random(), numeric_random(), timestamp_random(), and timestamptz_random().
◆ int4random()
◆ int8random()
◆ numeric_random()
◆ setseed()
Definition at line 75 of file pseudorandomfuncs.c.
76{
78
79 if (seed < -1 || seed > 1 || isnan(seed))
81 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
82 errmsg("setseed parameter %g is out of allowed range [-1,1]",
83 seed));
84
87
89}
void pg_prng_fseed(pg_prng_state *state, double fseed)
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_FLOAT8, pg_prng_fseed(), PG_RETURN_VOID, prng_seed_set, and prng_state.
Referenced by assign_random_seed().
◆ timestamp_random()
Definition at line 229 of file pseudorandomfuncs.c.
230{
234
236
239 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
240 errmsg("lower and upper bounds must be finite"));
241
243
245
247}
#define TIMESTAMP_IS_NOEND(j)
#define TIMESTAMP_IS_NOBEGIN(j)
#define PG_GETARG_TIMESTAMP(n)
#define PG_RETURN_TIMESTAMP(x)
References CHECK_RANGE_BOUNDS, ereport, errcode(), errmsg(), ERROR, initialize_prng(), PG_GETARG_TIMESTAMP, pg_prng_int64_range(), PG_RETURN_TIMESTAMP, prng_state, TIMESTAMP_IS_NOBEGIN, and TIMESTAMP_IS_NOEND.
◆ timestamptz_random()
Definition at line 255 of file pseudorandomfuncs.c.
256{
260
262
265 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
266 errmsg("lower and upper bounds must be finite"));
267
269
271
273}
#define PG_GETARG_TIMESTAMPTZ(n)
#define PG_RETURN_TIMESTAMPTZ(x)
References CHECK_RANGE_BOUNDS, ereport, errcode(), errmsg(), ERROR, initialize_prng(), PG_GETARG_TIMESTAMPTZ, pg_prng_int64_range(), PG_RETURN_TIMESTAMPTZ, prng_state, TIMESTAMP_IS_NOBEGIN, and TIMESTAMP_IS_NOEND.
◆ prng_seed_set
| bool prng_seed_set = false | static |
|---|
◆ prng_state
Definition at line 26 of file pseudorandomfuncs.c.
Referenced by choose_dsm_implementation(), date_random(), drandom(), drandom_normal(), initialize_prng(), int4random(), int8random(), numeric_random(), setseed(), timestamp_random(), and timestamptz_random().