blob: d8e6895a6efe77cfea9bbbba4ea453a8c51bd4ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/*------------------------------------------------------------------------
*
* geqo_random.c
* random number generator
*
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/backend/optimizer/geqo/geqo_random.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "optimizer/geqo_random.h"
void
geqo_set_seed(PlannerInfo *root, double seed)
{
GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
/*
* XXX. This seeding algorithm could certainly be improved - but it is not
* critical to do so.
*/
memset(private->random_state, 0, sizeof(private->random_state));
memcpy(private->random_state,
&seed,
Min(sizeof(private->random_state), sizeof(seed)));
}
double
geqo_rand(PlannerInfo *root)
{
GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private;
return pg_erand48(private->random_state);
}
|