java.lang.Object
io.jenetics.internal.math.Randoms
Some random helper functions.
- Since:
- 1.4
- Version:
- 7.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic IntStreamindexes(RandomGenerator random, int n, double p) Create anIntStreamwhich creates random indexes within the given range and the index probability.static IntStreamindexes(RandomGenerator random, int start, int end, double p) Create anIntStreamwhich creates random indexes within the given range and the index probability.static StringnextASCIIString(int length, RandomGenerator random) static StringnextASCIIString(RandomGenerator random) static bytenextByte(RandomGenerator random) static charnextChar(RandomGenerator random) static shortnextShort(RandomGenerator random) static longseed()Calculating a 64-bit seed value which can be used for initializing PRNGs.static byte[]seed(byte[] seed) Fills the given byte array with random bytes, created by successive calls of theseed()method.static longseed(long base) Uses the givenbasevalue to create a reasonable safe seed value.static byte[]seedBytes(int length) Create a new seed byte array of the given length.static doubletoDouble(int a, int b) static doubletoDouble(long a) static doubletoDouble2(int a, int b) static doubletoDouble2(long a) static floattoFloat(int a) static floattoFloat(long a) static floattoFloat2(int a) static floattoFloat2(long a)
-
Method Details
-
nextByte
-
nextChar
-
nextShort
-
nextASCIIString
-
nextASCIIString
-
toFloat
-
toFloat
-
toDouble
-
toDouble
-
toFloat2
-
toFloat2
-
toDouble2
-
toDouble2
-
indexes
Create anIntStreamwhich creates random indexes within the given range and the index probability.- Parameters:
random- the random engine used for calculating the random indexesstart- the start index (inclusively)end- the end index (exclusively)p- the index selection probability- Returns:
- a new random index stream
- Throws:
IllegalArgumentException- ifpis not a valid probability.- Since:
- 3.0
-
indexes
Create anIntStreamwhich creates random indexes within the given range and the index probability.- Parameters:
random- the random engine used for calculating the random indexesn- the end index (exclusively). The start index is zero.p- the index selection probability- Returns:
- a new random index stream
- Throws:
IllegalArgumentException- ifpis not a valid probability.NullPointerException- if the givenrandomengine isnull.- Since:
- 3.0
-
seedBytes
Create a new seed byte array of the given length.- Parameters:
length- the length of the returned byte array.- Returns:
- a new seed byte array of the given length
- Throws:
NegativeArraySizeException- if the given length is smaller than zero.- See Also:
-
seed
Fills the given byte array with random bytes, created by successive calls of theseed()method.- Parameters:
seed- the byte array seed to fill with random bytes.- Returns:
- the given byte array, for method chaining.
- Throws:
NullPointerException- if theseedarray isnull.- See Also:
-
seed
Calculating a 64-bit seed value which can be used for initializing PRNGs. This method uses a combination ofSystem.nanoTime()andnew Object().hashCode()calls to create a reasonable safe seed value:This method passes all the statistical tests of the dieharder test suite—executed on a linux machine with JDK version 1.7. Since there is no prove that this will the case for every Java version and OS, it is recommended to only use this method for seeding other PRNGs.public static long seed() { return seed(System.nanoTime()); }- Returns:
- the random seed value.
- See Also:
-
seed
Uses the givenbasevalue to create a reasonable safe seed value. This is done by combining it with values ofnew Object().hashCode():public static long seed(final long base) { final long objectHashSeed = ((long)(new Object().hashCode()) << 32) | new Object().hashCode(); long seed = base^objectHashSeed; seed ^= seed << 17; seed ^= seed >>> 31; seed ^= seed << 8; return seed; }- Parameters:
base- the base value of the seed to create- Returns:
- the created seed value.
-