aboutsummaryrefslogtreecommitdiffstats
path: root/random_bits.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-02 18:02:13 +0200
committerMattias Andrée <maandree@kth.se>2024-09-02 18:02:13 +0200
commit6f2ccb15b1599700dc6c9c2388609eccca10a608 (patch)
treed84732290af6e0dfac683eaf2ceea4bd4f7f2493 /random_bits.c
parentAdd TODO file (diff)
downloadlibsimple-6f2ccb15b1599700dc6c9c2388609eccca10a608.tar.gz
libsimple-6f2ccb15b1599700dc6c9c2388609eccca10a608.tar.bz2
libsimple-6f2ccb15b1599700dc6c9c2388609eccca10a608.tar.xz
m + add libsimple_random_bytes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--random_bits.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/random_bits.c b/random_bits.c
index 528b09e..a6d95a2 100644
--- a/random_bits.c
+++ b/random_bits.c
@@ -14,8 +14,10 @@ libsimple_random_bits(size_t bits, void *unused)
bits -= 8;
}
- ret <<= bits;
- ret |= (uintmax_t)(rand() & ((1 << bits) - 1));
+ if (bits) {
+ ret <<= bits;
+ ret |= (uintmax_t)(rand() & ((1 << bits) - 1));
+ }
(void) unused;
return ret;