mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ion] Simulator/Emscripten/Blackbox: correct random implementation
This commit is contained in:
committed by
EmilieNumworks
parent
be26a78979
commit
4f3290514f
@@ -3,10 +3,9 @@
|
||||
|
||||
uint32_t Ion::random() {
|
||||
/* rand() returns a pseudo-random integral number in the range between 0 and
|
||||
* RAND_MAX which is garantueed to be at least 32767.*/
|
||||
uint32_t result = 0;
|
||||
for (int i = 0; i < 131077; i++) {
|
||||
result += rand();
|
||||
}
|
||||
return result;
|
||||
* RAND_MAX. We assert that RAND_MAX is at least 8 bit, this way we can merge
|
||||
* four rand() calls to create a single 32 bit value. Merging is done using
|
||||
* XOR, whose output is as likely to be a 1 as a 0. */
|
||||
static_assert(RAND_MAX >= (1<<8), "RAND_MAX is too small");
|
||||
return (rand() << 24) ^ (rand() << 16) ^ (rand() << 8) ^ rand();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user