diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2022-07-28 09:18:01 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2022-08-01 14:37:24 -0300 |
commit | c622ac1b8662908b595ec1a19e401ad6a629f52c (patch) | |
tree | 3f45901eabfdbcb7688b68d22f8cf55d07eaf4c1 /conform/Makefile | |
parent | 7187efd0aa270c83c428ea6cd0e1cffc34b41a74 (diff) | |
download | glibc-c622ac1b8662908b595ec1a19e401ad6a629f52c.zip glibc-c622ac1b8662908b595ec1a19e401ad6a629f52c.tar.gz glibc-c622ac1b8662908b595ec1a19e401ad6a629f52c.tar.bz2 |
stdlib: Simplify arc4random_uniform
It uses the bitmask with rejection [1], which calculates a mask
being the lowest power of two bounding the request upper bound,
successively queries new random values, and rejects values
outside the requested range.
Performance-wise, there is no much gain in trying to conserve
bits since arc4random is wrapper on getrandom syscall. It should
be cheaper to just query a uint32_t value. The algorithm also
avoids modulo and divide operations, which might be costly
depending of the architecture.
[1] https://www.pcg-random.org/posts/bounded-rands.html
Reviewed-by: Yann Droneaud <ydroneaud@opteya.com>
Diffstat (limited to 'conform/Makefile')
0 files changed, 0 insertions, 0 deletions