Package org.elasticsearch.common
Class Randomness
java.lang.Object
org.elasticsearch.common.Randomness
Provides factory methods for producing reproducible sources of
randomness. Reproducible sources of randomness contribute to
reproducible tests. When running the Elasticsearch test suite, the
test runner will establish a global random seed accessible via the
system property "tests.seed". By seeding a random number generator
with this global seed, we ensure that instances of Random produced
with this class produce reproducible sources of randomness under
when running under the Elasticsearch test suite. Alternatively,
a reproducible source of randomness can be produced by providing a
setting a reproducible seed. When running the Elasticsearch server
process, non-reproducible sources of randomness are provided (unless
a setting is provided for a module that exposes a seed setting (e.g.,
NodeEnvironment#NODE_ID_SEED_SETTING)).
-
Method Summary
Modifier and TypeMethodDescriptionstatic SecureRandom
Provides a secure source of randomness.static Random
get()
Provides a source of randomness that is reproducible when running under the Elasticsearch test suite, and otherwise produces a non-reproducible source of randomness.static Random
Provides a reproducible source of randomness seeded by a long seed in the settings with the key setting.static void
-
Method Details
-
get
Provides a reproducible source of randomness seeded by a long seed in the settings with the key setting.- Parameters:
settings
- the settings containing the seedsetting
- the setting to access the seed- Returns:
- a reproducible source of randomness
-
get
Provides a source of randomness that is reproducible when running under the Elasticsearch test suite, and otherwise produces a non-reproducible source of randomness. Reproducible sources of randomness are created when the system property "tests.seed" is set and the security policy allows reading this system property. Otherwise, non-reproducible sources of randomness are created.- Returns:
- a source of randomness
- Throws:
IllegalStateException
- if running tests but was not able to acquire an instance of Random from RandomizedContext or tests are running but tests.seed is not set
-
createSecure
Provides a secure source of randomness. This acts exactly similar toget()
, but returning a newSecureRandom
. -
shuffle
-