Line data Source code
1 : /*------------------------------------------------------------------------ 2 : * 3 : * geqo_random.c 4 : * random number generator 5 : * 6 : * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group 7 : * Portions Copyright (c) 1994, Regents of the University of California 8 : * 9 : * src/backend/optimizer/geqo/geqo_random.c 10 : * 11 : *------------------------------------------------------------------------- 12 : */ 13 : 14 : #include "postgres.h" 15 : 16 : #include "optimizer/geqo_random.h" 17 : 18 : 19 : void 20 6 : geqo_set_seed(PlannerInfo *root, double seed) 21 : { 22 6 : GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private; 23 : 24 6 : pg_prng_fseed(&private->random_state, seed); 25 6 : } 26 : 27 : double 28 780 : geqo_rand(PlannerInfo *root) 29 : { 30 780 : GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private; 31 : 32 780 : return pg_prng_double(&private->random_state); 33 : } 34 : 35 : int 36 2310 : geqo_randint(PlannerInfo *root, int upper, int lower) 37 : { 38 2310 : GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private; 39 : 40 : /* 41 : * In current usage, "lower" is never negative so we can just use 42 : * pg_prng_uint64_range directly. 43 : */ 44 2310 : return (int) pg_prng_uint64_range(&private->random_state, lower, upper); 45 : }