Skip to content

Commit

Permalink
Mix all the bits in hydro_random_rbit()
Browse files Browse the repository at this point in the history
Fixes #51
  • Loading branch information
jedisct1 committed Apr 17, 2019
1 parent 471b749 commit cf7ca55
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions impl/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ static TLS struct {
#include <Arduino.h>

static bool
hydro_random_rbit(unsigned int x)
hydro_random_rbit(uint16_t x)
{
size_t i;
bool res = 0;
uint8_t x8;

for (i = 0; i < sizeof x; i++) {
res ^= ((x >> i) & 1);
}
return res;
x8 = ((uint8_t) (x >> 8)) ^ (uint8_t) x;
x8 = (x8 >> 4) ^ (x8 & 0xf);
x8 = (x8 >> 2) ^ (x8 & 0x3);
x8 = (x8 >> 1) ^ x8;

return (bool) (x8 & 1);
}

static int
Expand Down

0 comments on commit cf7ca55

Please sign in to comment.