1Data::Entropy(3) User Contributed Perl Documentation Data::Entropy(3)
2
3
4
6 Data::Entropy - entropy (randomness) management
7
9 use Data::Entropy qw(entropy_source);
10
11 $i = entropy_source->get_int(12345);
12
13 use Data::Entropy qw(with_entropy_source);
14
15 with_entropy_source $source, sub {
16 @a = shuffle(@a);
17 };
18
20 This module maintains a concept of a current selection of entropy
21 source. Algorithms that require entropy, such as those in
22 Data::Entropy::Algorithms, can use the source nominated by this module,
23 avoiding the need for entropy source objects to be explicitly passed
24 around. This is convenient because usually one entropy source will be
25 used for an entire program run and so an explicit entropy source
26 parameter would rarely vary. There is also a default entropy source,
27 avoiding the need to explicitly configure a source at all.
28
29 If nothing is done to set a source then it defaults to the use of
30 Rijndael (AES) in counter mode (see
31 Data::Entropy::RawSource::CryptCounter and Crypt::Rijndael), keyed
32 using Perl's built-in "rand" function. This gives a data stream that
33 looks like concentrated entropy, but really only has at most the
34 entropy of the "rand" seed. Within a single run it is
35 cryptographically difficult to detect the correlation between parts of
36 the pseudo-entropy stream. If more true entropy is required then it is
37 necessary to configure a different entropy source.
38
40 entropy_source
41 Returns the current entropy source, a "Data::Entropy::Source"
42 object. This will be the source passed to the innermost call to
43 "with_entropy_source", if any, or otherwise the default entropy
44 source.
45
46 with_entropy_source SOURCE, CLOSURE
47 The SOURCE is selected, so that it will be returned by
48 "entropy_source", and CLOSURE is called (with no arguments). The
49 SOURCE is selected only during the dynamic scope of the call; after
50 CLOSURE finishes, by whatever means, the previously selected
51 entropy source is restored.
52
53 SOURCE is normally a "Data::Entropy::Source" object.
54 Alternatively, it may be "undef" to cause use of the default
55 entropy source. It may also be a reference to a function of no
56 arguments, which will be called to generate the actual source only
57 if required. This avoids unnecessarily initialising the source
58 object if it is uncertain whether any entropy will be required.
59 The source-generating closure may return a normal source or
60 "undef", but not another function reference.
61
63 Data::Entropy::Algorithms, Data::Entropy::Source
64
66 Andrew Main (Zefram) <zefram@fysh.org>
67
69 Copyright (C) 2006, 2007, 2009, 2011 Andrew Main (Zefram)
70 <zefram@fysh.org>
71
73 This module is free software; you can redistribute it and/or modify it
74 under the same terms as Perl itself.
75
76
77
78perl v5.32.0 2020-07-28 Data::Entropy(3)