Java Random class
Java Random class is used to generate a stream of pseudorandom numbers. The algorithms implemented by Random class use a protected utility method than can supply up to 32 pseudorandomly generated bits on each invocation.
Methods
Methods |
Description |
doubles() |
Returns an unlimited stream of pseudorandom double values. |
ints() |
Returns an unlimited stream of pseudorandom int values. |
longs() |
Returns an unlimited stream of pseudorandom long values. |
next() |
Generates the next pseudorandom number. |
nextBoolean() |
Returns the next uniformly distributed pseudorandom boolean value from the random number generator's sequence |
nextByte() |
Generates random bytes and puts them into a specified byte array. |
nextDouble() |
Returns the next pseudorandom Double value between 0.0 and 1.0 from the random number generator's sequence |
nextFloat() |
Returns the next uniformly distributed pseudorandom Float value between 0.0 and 1.0 from this random number generator's sequence |
nextGaussian() |
Returns the next pseudorandom Gaussian double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence. |
nextInt() |
Returns a uniformly distributed pseudorandom int value generated from this random number generator's sequence |
nextLong() |
Returns the next uniformly distributed pseudorandom long value from the random number generator's sequence. |
setSeed() |
Sets the seed of this random number generator using a single long seed. |
Example 1
Test it Now
Output:
Longs value : java.util.stream.LongPipeline$Head@14ae5a5
Random boolean value : true
Random bytes = ( 57 77 8 67 -122 -71 -79 -62 53 19 )
Example 2
Test it Now
Output:
Random Integer value : 1294094433
Seed value : -1150867590
Random Long value : -7322354119883315205
|