java.lang.Object
io.jenetics.internal.math.Randoms
Some random helper functions.
- Since:
- 1.4
- Version:
- 7.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic IntStream
indexes
(RandomGenerator random, int n, double p) Create anIntStream
which creates random indexes within the given range and the index probability.static IntStream
indexes
(RandomGenerator random, int start, int end, double p) Create anIntStream
which creates random indexes within the given range and the index probability.static String
nextASCIIString
(int length, RandomGenerator random) static String
nextASCIIString
(RandomGenerator random) static byte
nextByte
(RandomGenerator random) static char
nextChar
(RandomGenerator random) static short
nextShort
(RandomGenerator random) static long
seed()
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 long
seed
(long base) Uses the givenbase
value to create a reasonable safe seed value.static byte[]
seedBytes
(int length) Create a new seed byte array of the given length.static double
toDouble
(int a, int b) static double
toDouble
(long a) static double
toDouble2
(int a, int b) static double
toDouble2
(long a) static float
toFloat
(int a) static float
toFloat
(long a) static float
toFloat2
(int a) static float
toFloat2
(long a)
-
Method Details
-
nextByte
-
nextChar
-
nextShort
-
nextASCIIString
-
nextASCIIString
-
toFloat
-
toFloat
-
toDouble
-
toDouble
-
toFloat2
-
toFloat2
-
toDouble2
-
toDouble2
-
indexes
Create anIntStream
which 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
- ifp
is not a valid probability.- Since:
- 3.0
-
indexes
Create anIntStream
which 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
- ifp
is not a valid probability.NullPointerException
- if the givenrandom
engine 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 theseed
array 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 givenbase
value 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.
-