aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2022-12-29 18:13:23 +0100
committerAlejandro Colomar <alx@kernel.org>2022-12-29 18:13:54 +0100
commit8341e8b683f1e9582956a8a98065865a96b0798f (patch)
tree83e9770059623bf56d0ef2d1ccf011de08c418d0
parent72b349dd8c209d7375d4d4f76e2315943d654ee9 (diff)
downloadman-pages-8341e8b683f1e9582956a8a98065865a96b0798f.tar.gz
rand.3: EXAMPLES: Show how to get a random seed
This is useful when testing many different cases, but repeatability is more important than quality of the random numbers. Cc: Jonny Grant <jg@jguk.org> Cc: Cristian Rodríguez <crrodriguez@opensuse.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--man3/rand.38
1 files changed, 8 insertions, 0 deletions
diff --git a/man3/rand.3 b/man3/rand.3
index 5b9e21abea..e7778655e5 100644
--- a/man3/rand.3
+++ b/man3/rand.3
@@ -190,6 +190,9 @@ The following program can be used to display the
pseudo-random sequence produced by
.BR rand ()
when given a particular seed.
+When the seed is
+.IR \-1 ,
+the program uses a random seed.
.PP
.in +4n
.\" SRC BEGIN (rand.c)
@@ -211,6 +214,11 @@ main(int argc, char *argv[])
seed = atoi(argv[1]);
nloops = atoi(argv[2]);
+ if (seed == \-1) {
+ seed = arc4random();
+ printf("seed: %u\en", seed);
+ }
+
srand(seed);
for (unsigned int j = 0; j < nloops; j++) {
r = rand();