Line data Source code
1 : /*------------------------------------------------------------------------
2 : *
3 : * geqo_random.c
4 : * random number generator
5 : *
6 : * Portions Copyright (c) 1996-2017, 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 1 : geqo_set_seed(PlannerInfo *root, double seed)
21 : {
22 1 : GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
23 :
24 : /*
25 : * XXX. This seeding algorithm could certainly be improved - but it is not
26 : * critical to do so.
27 : */
28 1 : memset(private->random_state, 0, sizeof(private->random_state));
29 1 : memcpy(private->random_state,
30 : &seed,
31 : Min(sizeof(private->random_state), sizeof(seed)));
32 1 : }
33 :
34 : double
35 540 : geqo_rand(PlannerInfo *root)
36 : {
37 540 : GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
38 :
39 540 : return pg_erand48(private->random_state);
40 : }
|