]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: give an example of using a seed for random operations
authorPádraig Brady <P@draigBrady.com>
Mon, 9 Feb 2015 20:58:47 +0000 (20:58 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 11 Feb 2015 00:31:39 +0000 (00:31 +0000)
* doc/coreutils.texi (Random sources):  Give an example using openssl,
generating a reproducible arbitrary amount of randomly distributed
data, given a seed value.

doc/coreutils.texi

index 87fb3dcb795370237829818805d60e2f7dce59a4..bb652aca5ff2b2c268cc78f3b2efa50b383c0adf 100644 (file)
@@ -1240,6 +1240,21 @@ operating system.
 To reproduce the results of an earlier invocation of a command, you
 can save some random data into a file and then use that file as the
 random source in earlier and later invocations of the command.
+@cindex random seed
+Rather than depending on a file, one can generate a reproducible
+arbitrary amount of pseudo-random data given a seed value, using
+for example:
+
+@example
+get_seeded_random()
+@{
+  seed="$1"
+  openssl enc -aes-256-ctr -pass pass:"$seed" -nosalt \
+    </dev/zero 2>/dev/null
+@}
+
+shuf -i1-100 --random-source=<(get_seeded_random 42)
+@end example
 
 @node Target directory
 @section Target directory