Exclusively use OAI_RNGSEED env variable everywhere
Hide normal table initialization of Ziggurat generator from outside to
force the usage of randominit() for RNG initialization. In this step,
remove the randominit() seed parameter and only rely on OAI_RNGSEED for
a consistent RNG initialization, as this parameter was used differently
("0" as fixed number or to force a random seed).
Now, only use OAI_RNGSEED env variable to force the usage of a fixed
seed.
This commit is contained in:
committed by
Robert Schmidt
parent
0e4ade9472
commit
a1b4220a91
@@ -93,7 +93,7 @@ int main() {
|
||||
{3420,2820},{1580,3940},{660,2100},{2740,1180},{2500,2500},
|
||||
{3580,3580},{3740,3140},{3020,3020},{4340,4140},{980,4300}
|
||||
};
|
||||
randominit(0);
|
||||
randominit();
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int tabl_len=0;
|
||||
double local_table[MCS_COUNT][9][9];
|
||||
|
||||
@@ -572,11 +572,6 @@ channel_desc_t *new_channel_desc_scm(uint8_t nb_tx,
|
||||
double path_loss_dB,
|
||||
float noise_power_dB)
|
||||
{
|
||||
// To create tables for normal distribution
|
||||
struct timespec t;
|
||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
tableNor((long) (t.tv_nsec % INT_MAX));
|
||||
|
||||
channel_desc_t *chan_desc = (channel_desc_t *)calloc(1,sizeof(channel_desc_t));
|
||||
|
||||
for(int i=0; i<max_chan; i++) {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "sim.h"
|
||||
|
||||
static inline void tableNor(unsigned long seed);
|
||||
static unsigned int urseed, iy, ir[98]; /// uniformrandom
|
||||
static bool tableNordDone = false; /// gaussZiggurat
|
||||
|
||||
@@ -49,14 +50,16 @@ void fill_random(void *buf, size_t sz)
|
||||
static const unsigned int a = 1664525lu;
|
||||
|
||||
/*!\brief Initialization routine for Uniform/Gaussian random number generators. */
|
||||
void randominit(unsigned long seed_init)
|
||||
// fix seed number by env variable OAI_RNGSEED
|
||||
void randominit()
|
||||
{
|
||||
unsigned long seed = seed_init;
|
||||
if (seed_init == 0)
|
||||
fill_random(&seed, sizeof(seed));
|
||||
unsigned long seed;
|
||||
const char* str_oai_rngseed = getenv("OAI_RNGSEED");
|
||||
if (str_oai_rngseed != NULL)
|
||||
if (str_oai_rngseed != NULL) {
|
||||
seed = atoi(str_oai_rngseed);
|
||||
} else {
|
||||
fill_random(&seed, sizeof(seed));
|
||||
}
|
||||
printf("Initializing random number generator, seed %lu\n", seed);
|
||||
|
||||
// initialize uniformrandom RNG
|
||||
@@ -71,7 +74,6 @@ void randominit(unsigned long seed_init)
|
||||
|
||||
// initialize gaussZiggurat RNG
|
||||
tableNor(seed);
|
||||
tableNordDone = true;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -164,7 +166,7 @@ double nfix(void)
|
||||
}
|
||||
|
||||
/*!Procedure to create tables for normal distribution kn,wn and fn. */
|
||||
void tableNor(unsigned long seed)
|
||||
static inline void tableNor(unsigned long seed)
|
||||
{
|
||||
jsr = seed;
|
||||
double dn = 3.442619855899;
|
||||
@@ -194,12 +196,11 @@ void tableNor(unsigned long seed)
|
||||
|
||||
double __attribute__ ((no_sanitize("address", "undefined"))) gaussZiggurat(double mean, double variance)
|
||||
{
|
||||
if (!tableNordDone) {
|
||||
// let's make reasonnable constant tables
|
||||
unsigned long seed;
|
||||
fill_random(&seed, sizeof(seed));
|
||||
tableNor(seed);
|
||||
if (!__builtin_expect(tableNordDone, 1)) {
|
||||
fprintf(stderr, "%s(): RNG not initialized, run randominit() first\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
hz = SHR3;
|
||||
iz = hz & 127;
|
||||
return hz != INT32_MIN && abs(hz) < kn[iz] ? hz * wn[iz] : nfix();
|
||||
|
||||
@@ -528,10 +528,9 @@ int gauss(unsigned int *gauss_LUT,unsigned char Nbits);
|
||||
|
||||
void fill_random(void *buf, size_t sz);
|
||||
double gaussdouble(double,double);
|
||||
void randominit(unsigned long seed_init);
|
||||
void randominit(); // fix seed number by env variable OAI_RNGSEED
|
||||
double uniformrandom(void);
|
||||
double gaussZiggurat(double mean, double variance);
|
||||
void tableNor(unsigned long seed);
|
||||
int freq_channel(channel_desc_t *desc,uint16_t nb_rb, int16_t n_samples,int scs);
|
||||
int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples,int scs);
|
||||
void term_freq_channel(void);
|
||||
|
||||
Reference in New Issue
Block a user