blob: 97100bcef4362857c310777d514091cbe1edccf1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
.TH ZRAND 3 libzahl
.SH NAME
zrand - Generate random a number
.SH SYNOPSIS
.nf
#include <zahl.h>
void zrand(z_t \fIr\fP, enum zranddev \fIdev\fP, enum zranddist \fIdist\fP, z_t \fImax\fP);
.fi
.SH DESCRIPTION
.B zrand
generates a random number and stores it in
.IR r .
.P
.I dev
selects the device
.B zrand
uses to generate random bits.
This value may be either of:
.TP
.B FAST_RANDOM
The fast, non-blocking random number generator.
This is /dev/urandom on Linux.
.TP
.B SECURE_RANDOM
The secure, blocking random number generator.
This is /dev/random on Linux.
.P
.I dist
selects the probably distribution of the
output
.IR r :
.TP
.B QUASIUNIFORM
Use the method of generation that is often
recommended for generating uniformally random
integers. This method has unnecessary
computational overhead and is not properly
uniform, but is is guaranteed to run in
constant time assuming the underlying device
for random bit generation does.
The generated number if be in the inclusive
range [0,
.IR max ].
.TP
.B UNIFORM
Generate a integer in the range [0,
.IR max ]
uniformally random.
.TP
.B MODUNIFORM
Slightly faster alternative to
.BR UNIFORM .
It is not truly uniform. It is biased
to the lower numbers, but the probably
if any number is either
.I p
or
.I 2p
for some parameter-dependent number
.IR p .
It uses the naïve approach of generating
a random number and modulation with the maximum
number. However, this implementation this
modulation by subtracting with the maximum number
if the generated number is greater.
.P
It is safe to call
.B zrand
with non-unique parameters.
|