about summary refs log tree commit diff
path: root/htl
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2022-07-28 09:18:01 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2022-08-01 14:37:24 -0300
commitc622ac1b8662908b595ec1a19e401ad6a629f52c (patch)
tree3f45901eabfdbcb7688b68d22f8cf55d07eaf4c1 /htl
parent7187efd0aa270c83c428ea6cd0e1cffc34b41a74 (diff)
downloadglibc-c622ac1b8662908b595ec1a19e401ad6a629f52c.tar.gz
glibc-c622ac1b8662908b595ec1a19e401ad6a629f52c.tar.xz
glibc-c622ac1b8662908b595ec1a19e401ad6a629f52c.zip
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 'htl')
0 files changed, 0 insertions, 0 deletions