00001 /*------------------------------------------------------------------------ 00002 * 00003 * geqo_random.c 00004 * random number generator 00005 * 00006 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00007 * Portions Copyright (c) 1994, Regents of the University of California 00008 * 00009 * src/backend/optimizer/geqo/geqo_random.c 00010 * 00011 *------------------------------------------------------------------------- 00012 */ 00013 00014 #include "postgres.h" 00015 00016 #include "optimizer/geqo_random.h" 00017 00018 00019 void 00020 geqo_set_seed(PlannerInfo *root, double seed) 00021 { 00022 GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private; 00023 00024 /* 00025 * XXX. This seeding algorithm could certainly be improved - but it is not 00026 * critical to do so. 00027 */ 00028 memset(private->random_state, 0, sizeof(private->random_state)); 00029 memcpy(private->random_state, 00030 &seed, 00031 Min(sizeof(private->random_state), sizeof(seed))); 00032 } 00033 00034 double 00035 geqo_rand(PlannerInfo *root) 00036 { 00037 GeqoPrivateData *private = (GeqoPrivateData *) root->join_search_private; 00038 00039 return pg_erand48(private->random_state); 00040 }