PostgreSQL Source Code: src/backend/utils/adt/pseudorandomfuncs.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
15
16#include <math.h>
17
21#include "utils/fmgrprotos.h"
24
25
28
29
30
31
32
33#define CHECK_RANGE_BOUNDS(rmin, rmax) \
34 do { \
35 if ((rmin) > (rmax)) \
36 ereport(ERROR, \
37 errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
38 errmsg("lower bound must be less than or equal to upper bound")); \
39 } while (0)
40
41
42
43
44
45
46static void
48{
50 {
51
52
53
54
55
57 {
60
61
64 }
66 }
67}
68
69
70
71
72
73
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}
90
91
92
93
94
95
98{
100
102
103
105
107}
108
109
110
111
112
113
116{
120 z;
121
123
124
126
127
128 result = (stddev * z) + mean;
129
131}
132
133
134
135
136
137
140{
144
146
148
150
152}
153
154
155
156
157
158
161{
165
167
169
171
173}
174
175
176
177
178
179
182{
186
187
188
190
192
194}
195
196
197
198
199
200
201
204{
208
210
213 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
214 errmsg("lower and upper bounds must be finite"));
215
217
219
221}
222
223
224
225
226
227
230{
234
236
239 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
240 errmsg("lower and upper bounds must be finite"));
241
243
245
247}
248
249
250
251
252
253
256{
260
262
265 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
266 errmsg("lower and upper bounds must be finite"));
267
269
271
273}
Numeric random_numeric(pg_prng_state *state, Numeric rmin, Numeric rmax)
TimestampTz GetCurrentTimestamp(void)
Datum now(PG_FUNCTION_ARGS)
#define TIMESTAMP_IS_NOEND(j)
#define TIMESTAMP_IS_NOBEGIN(j)
#define PG_RETURN_DATEADT(x)
#define DATE_IS_NOBEGIN(j)
#define PG_GETARG_DATEADT(n)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_GETARG_FLOAT8(n)
#define PG_RETURN_FLOAT8(x)
#define PG_RETURN_INT64(x)
#define PG_GETARG_INT64(n)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_NUMERIC(n)
#define PG_RETURN_NUMERIC(x)
int64 pg_prng_int64_range(pg_prng_state *state, int64 rmin, int64 rmax)
double pg_prng_double(pg_prng_state *state)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
double pg_prng_double_normal(pg_prng_state *state)
void pg_prng_fseed(pg_prng_state *state, double fseed)
#define pg_prng_strong_seed(state)
static void initialize_prng(void)
Datum numeric_random(PG_FUNCTION_ARGS)
static pg_prng_state prng_state
Datum timestamp_random(PG_FUNCTION_ARGS)
Datum date_random(PG_FUNCTION_ARGS)
Datum int4random(PG_FUNCTION_ARGS)
Datum timestamptz_random(PG_FUNCTION_ARGS)
Datum setseed(PG_FUNCTION_ARGS)
static bool prng_seed_set
Datum drandom(PG_FUNCTION_ARGS)
#define CHECK_RANGE_BOUNDS(rmin, rmax)
Datum drandom_normal(PG_FUNCTION_ARGS)
Datum int8random(PG_FUNCTION_ARGS)
#define PG_GETARG_TIMESTAMP(n)
#define PG_RETURN_TIMESTAMP(x)
#define PG_GETARG_TIMESTAMPTZ(n)
#define PG_RETURN_TIMESTAMPTZ(x)