1/*------------------------------------------------------------------------
2 *
3 * geqo_random.c
4 * random number generator
5 *
6 * Portions Copyright (c) 1996-2019, 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
19void
20geqo_set_seed(PlannerInfo *root, double seed)
21{
22 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 memset(private->random_state, 0, sizeof(private->random_state));
29 memcpy(private->random_state,
30 &seed,
31 Min(sizeof(private->random_state), sizeof(seed)));
32}
33
34double
35geqo_rand(PlannerInfo *root)
36{
37 GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
38
39 return pg_erand48(private->random_state);
40}
41