commit c5f0bedd07467c089b0eca567828508abfcc9b6d
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Fri Mar 25 13:33:41 2016 +0100
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Fri Mar 25 13:33:41 2016 +0100
zrand: add DEFAULT_RANDOM and FASTEST_RANDOM
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/man/zrand.3 b/man/zrand.3
index 97100bc..6092c5e 100644
--- a/man/zrand.3
+++ b/man/zrand.3
_AT_@ -18,6 +18,29 @@ selects the device
uses to generate random bits.
This value may be either of:
.TP
+.B DEFAULT_RANDOM
+This is a version-dependent alias for the
+default random number generator. That is,
+using this option will cause
+.B zrand
+to select the default random number generator.
+Which random number generator is actually
+selected may change between versions of
+.B zrand.
+
+The selection will be a balance between randomness
+and performance.
+.TP
+.B FASTEST_RANDOM
+This is a version-dependent alias for the
+fastest random number generator. That is,
+using this option will cause
+.B zrand
+to select the fastest random number generator.
+Which random number generator is actually
+selected may change between versions of
+.B zrand.
+.TP
.B FAST_RANDOM
The fast, non-blocking random number generator.
This is /dev/urandom on Linux.
diff --git a/src/zrand.c b/src/zrand.c
index 17968af..5945ad8 100644
--- a/src/zrand.c
+++ b/src/zrand.c
_AT_@ -55,6 +55,8 @@ zrand(z_t r, enum zranddev dev, enum zranddist dist, z_t n)
int fd;
switch (dev) {
+ case DEFAULT_RANDOM:
+ case FASTEST_RANDOM:
case FAST_RANDOM:
pathname = FAST_RANDOM_PATHNAME;
break;
diff --git a/test.c b/test.c
index de92ccb..bcb6815 100644
--- a/test.c
+++ b/test.c
_AT_@ -731,7 +731,7 @@ main(void)
zrand(b, SECURE_RANDOM, UNIFORM, d);
assert(zcmp(b, _0), >= 0);
assert(zcmp(b, d), <= 0);
- zrand(c, FAST_RANDOM, UNIFORM, d);
+ zrand(c, FASTEST_RANDOM, UNIFORM, d);
assert(zcmp(c, _0), >= 0);
assert(zcmp(c, d), <= 0);
assert(zcmp(a, b), != 0);
_AT_@ -739,13 +739,13 @@ main(void)
assert(zcmp(b, c), != 0);
zsetu(d, 100000UL);
- zrand(a, FAST_RANDOM, QUASIUNIFORM, d);
+ zrand(a, DEFAULT_RANDOM, QUASIUNIFORM, d);
assert(zcmp(a, _0), >= 0);
assert(zcmp(a, d), <= 0);
- zrand(b, FAST_RANDOM, QUASIUNIFORM, d);
+ zrand(b, DEFAULT_RANDOM, QUASIUNIFORM, d);
assert(zcmp(b, _0), >= 0);
assert(zcmp(b, d), <= 0);
- zrand(c, FAST_RANDOM, QUASIUNIFORM, d);
+ zrand(c, DEFAULT_RANDOM, QUASIUNIFORM, d);
assert(zcmp(c, _0), >= 0);
assert(zcmp(c, d), <= 0);
assert(zcmp(a, b), != 0);
_AT_@ -753,13 +753,13 @@ main(void)
assert(zcmp(b, c), != 0);
zsetu(d, 100000UL);
- zrand(a, FAST_RANDOM, MODUNIFORM, d);
+ zrand(a, DEFAULT_RANDOM, MODUNIFORM, d);
assert(zcmp(a, _0), >= 0);
assert(zcmp(a, d), <= 0);
- zrand(b, FAST_RANDOM, MODUNIFORM, d);
+ zrand(b, DEFAULT_RANDOM, MODUNIFORM, d);
assert(zcmp(b, _0), >= 0);
assert(zcmp(b, d), <= 0);
- zrand(c, FAST_RANDOM, MODUNIFORM, d);
+ zrand(c, DEFAULT_RANDOM, MODUNIFORM, d);
assert(zcmp(c, _0), >= 0);
assert(zcmp(c, d), <= 0);
assert(zcmp(a, b), != 0);
diff --git a/zahl.h b/zahl.h
index 1ac6237..e49a6a0 100644
--- a/zahl.h
+++ b/zahl.h
_AT_@ -48,7 +48,9 @@ enum zprimality {
enum zranddev {
FAST_RANDOM = 0, /* Random numbers are generated directly from /dev/urandom. */
- SECURE_RANDOM /* Random numbers are generated directly from /dev/random. */
+ SECURE_RANDOM, /* Random numbers are generated directly from /dev/random. */
+ DEFAULT_RANDOM, /* Select the default random number generator. */
+ FASTEST_RANDOM /* Select the fastest random number generator. */
};
enum zranddist {
Received on Fri Mar 25 2016 - 15:28:11 CET
This archive was generated by hypermail 2.3.0
: Fri Mar 25 2016 - 15:36:21 CET