diff options
author | ache <ache@FreeBSD.org> | 2008-07-22 11:33:49 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2008-07-22 11:33:49 +0000 |
commit | 06e39c3b3642e5c3f83618f9864d21117278b68f (patch) | |
tree | 374d7148320af4df512b9186deb03fbb60ef34de /lib/libc/gen/arc4random.3 | |
parent | 31393d8a077bd95c3fa9ef23a427ae3c2c7860e6 (diff) | |
download | FreeBSD-src-06e39c3b3642e5c3f83618f9864d21117278b68f.zip FreeBSD-src-06e39c3b3642e5c3f83618f9864d21117278b68f.tar.gz |
Add arc4random_uniform() function (to avoid "modulo bias")
Obtained from: OpenBSD
Diffstat (limited to 'lib/libc/gen/arc4random.3')
-rw-r--r-- | lib/libc/gen/arc4random.3 | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/libc/gen/arc4random.3 b/lib/libc/gen/arc4random.3 index 5af38ce..be1f690 100644 --- a/lib/libc/gen/arc4random.3 +++ b/lib/libc/gen/arc4random.3 @@ -36,6 +36,7 @@ .Sh NAME .Nm arc4random , .Nm arc4random_buf , +.Nm arc4random_uniform , .Nm arc4random_stir , .Nm arc4random_addrandom .Nd arc4 random number generator @@ -47,6 +48,8 @@ .Fn arc4random "void" .Ft void .Fn arc4random_buf "void *buf" "size_t nbytes" +.Ft u_int32_t +.Fn arc4random_uniform "u_int32_t upper_bound" .Ft void .Fn arc4random_stir "void" .Ft void @@ -78,6 +81,14 @@ of length .Fa nbytes with ARC4-derived random data. .Pp +.Fn arc4random_uniform +will return a uniformly distributed random number less than +.Fa upper_bound . +.Fn arc4random_uniform +is recommended over constructions like +.Dq Li arc4random() % upper_bound +as it avoids "modulo bias" when the upper bound is not a power of two. +.Pp The .Fn arc4random_stir function reads data from |