From e6341323a8da64b18e9af3e75a4578230702d61c Mon Sep 17 00:00:00 2001 From: Dean Rasheed Date: Wed, 27 Mar 2024 10:12:39 +0000 Subject: Add functions to generate random numbers in a specified range. This adds 3 new variants of the random() function: random(min integer, max integer) returns integer random(min bigint, max bigint) returns bigint random(min numeric, max numeric) returns numeric Each returns a random number x in the range min <= x <= max. For the numeric function, the number of digits after the decimal point is equal to the number of digits that "min" or "max" has after the decimal point, whichever has more. The main entry points for these functions are in a new C source file. The existing random(), random_normal(), and setseed() functions are moved there too, so that they can all share the same PRNG state, which is kept private to that file. Dean Rasheed, reviewed by Jian He, David Zhang, Aleksander Alekseev, and Tomas Vondra. Discussion: https://postgr.es/m/CAEZATCV89Vxuq93xQdmc0t-0Y2zeeNQTdsjbmV7dyFBPykbV4Q@mail.gmail.com --- src/include/utils/numeric.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/include/utils/numeric.h') diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h index 2f7184e299b..43c75c436fe 100644 --- a/src/include/utils/numeric.h +++ b/src/include/utils/numeric.h @@ -14,6 +14,7 @@ #ifndef _PG_NUMERIC_H_ #define _PG_NUMERIC_H_ +#include "common/pg_prng.h" #include "fmgr.h" /* @@ -103,4 +104,7 @@ extern Numeric numeric_mod_opt_error(Numeric num1, Numeric num2, extern int32 numeric_int4_opt_error(Numeric num, bool *have_error); extern int64 numeric_int8_opt_error(Numeric num, bool *have_error); +extern Numeric random_numeric(pg_prng_state *state, + Numeric rmin, Numeric rmax); + #endif /* _PG_NUMERIC_H_ */ -- cgit v1.2.3