Commit 6ceaf084 authored by laurent's avatar laurent Committed by Roberto Louro Magueta

remove usage of /dev/random in case openshit has a problem with this

remove usage of /dev/random in case openshit has a problem with this
parent 2d46638a
...@@ -530,12 +530,9 @@ channel_desc_t *new_channel_desc_scm(uint8_t nb_tx, ...@@ -530,12 +530,9 @@ channel_desc_t *new_channel_desc_scm(uint8_t nb_tx,
float noise_power_dB) { float noise_power_dB) {
// To create tables for normal distribution // To create tables for normal distribution
uint64_t rand; struct timespec t;
FILE *h = fopen("/dev/random", "r"); clock_gettime(CLOCK_MONOTONIC, &t);
if (fread(&rand, sizeof(rand), 1, h) != 1) { tableNor((long)(t.tv_nsec%INT_MAX));
LOG_W(HW, "Simulator can't read /dev/random\n");
}
tableNor(rand);
channel_desc_t *chan_desc = (channel_desc_t *)calloc(1,sizeof(channel_desc_t)); channel_desc_t *chan_desc = (channel_desc_t *)calloc(1,sizeof(channel_desc_t));
......
...@@ -110,6 +110,7 @@ double __attribute__ ((no_sanitize_address)) gaussdouble(double mean, double var ...@@ -110,6 +110,7 @@ double __attribute__ ((no_sanitize_address)) gaussdouble(double mean, double var
} }
// Ziggurat // Ziggurat
static bool tableNordDone=false;
static double wn[128], fn[128]; static double wn[128], fn[128];
static uint32_t iz, jz, jsr = 123456789, kn[128]; static uint32_t iz, jz, jsr = 123456789, kn[128];
static int32_t hz; static int32_t hz;
...@@ -171,12 +172,18 @@ void tableNor(unsigned long seed) ...@@ -171,12 +172,18 @@ void tableNor(unsigned long seed)
fn[i] = (exp(-0.5 * dn * dn)); fn[i] = (exp(-0.5 * dn * dn));
wn[i] = (dn / m1); wn[i] = (dn / m1);
} }
tableNordDone=true;
return; return;
} }
double __attribute__ ((no_sanitize_address)) gaussZiggurat(double mean, double variance) double __attribute__ ((no_sanitize_address)) gaussZiggurat(double mean, double variance)
{ {
if (!tableNordDone) {
// let's make reasonnable constant tables
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
tableNor((long)(t.tv_nsec%INT_MAX));
}
hz = SHR3; hz = SHR3;
iz = hz & 127; iz = hz & 127;
return abs(hz) < kn[iz] ? hz * wn[iz] : nfix(); return abs(hz) < kn[iz] ? hz * wn[iz] : nfix();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment