MCPcopy Create free account
hub / github.com/apache/cloudberry / getrand

Function getrand

src/bin/pgbench/pgbench.c:931–944  ·  view source on GitHub ↗

* Random number generator: uniform distribution from min to max inclusive. * * Although the limits are expressed as int64, you can't generate the full * int64 range in one call, because the difference of the limits mustn't * overflow int64. In practice it's unwise to ask for more than an int32 * range, because of the limited precision of pg_erand48(). */

Source from the content-addressed store, hash-verified

929 * range, because of the limited precision of pg_erand48().
930 */
931static int64
932getrand(RandomState *random_state, int64 min, int64 max)
933{
934 /*
935 * Odd coding is so that min and max have approximately the same chance of
936 * being selected as do numbers between them.
937 *
938 * pg_erand48() is thread-safe and concurrent, which is why we use it
939 * rather than random(), which in glibc is non-reentrant, and therefore
940 * protected by a mutex, and therefore a bottleneck on machines with many
941 * CPUs.
942 */
943 return min + (int64) ((max - min + 1) * pg_erand48(random_state->xseed));
944}
945
946/*
947 * random number generator: exponential distribution from min to max inclusive.

Callers 3

permuteFunction · 0.85
evalStandardFuncFunction · 0.85
chooseScriptFunction · 0.85

Calls 1

pg_erand48Function · 0.85

Tested by

no test coverage detected