Optimized byte random generator

master
Xavier Arteaga 3 years ago committed by Xavier Arteaga
parent 475c033440
commit ef4c978d72

@ -36,6 +36,23 @@ public:
return dist(*mt19937);
}
void byte_vector(uint8_t* buffer, uint32_t n)
{
if (buffer == NULL || n == 0) {
return;
}
uint32_t i = 0;
uint32_t* buffer_u32 = (uint32_t*)buffer;
for (; i < n / sizeof(uint32_t); i++) {
buffer_u32[i] = (uint32_t)(*mt19937)();
}
i *= (uint32_t)sizeof(uint32_t);
for (; i < n; i++) {
buffer[i] = (uint8_t)((*mt19937)() & 0xffUL);
}
}
float gauss_dist(float sigma)
{
std::normal_distribution<float> dist(sigma);
@ -115,9 +132,11 @@ bool srsran_random_bool(srsran_random_t q, float prob_true)
void srsran_random_bit_vector(srsran_random_t q, uint8_t* c, uint32_t nsamples)
{
for (uint32_t i = 0; i < nsamples; i++) {
c[i] = (uint8_t)srsran_random_uniform_int_dist(q, 0, 1);
if (q == nullptr) {
return;
}
auto* h = (random_wrap*)q;
h->byte_vector(c, nsamples);
}
void srsran_random_free(srsran_random_t q)

Loading…
Cancel
Save