
("Int ThreadLocalRandom value: "+threadRandom.nextInt()) ThreadLocalRandom threadRandom = ThreadLocalRandom.current()
#Math.random java. generator
The current() method returns the instance of the ThreadLocalRandom class and call one of the randon number generator methods nextInt(), nextLong(), nextDouble(), nextFloat(), nextBoolean() or nextGaussian(). ThreadLocalRandom class doesn’t support explicit seeding, unlike Random class, to ensure true randomness. The ThreadLocalRandom random number generator is isolated to the current instance, a new instance will be created for each thread with an internally generated seed. Though Random class instance is also thread-safe concurrent usage will result in contention and poor performance. ThreadLocalRandom was introduced in Java 7, ThreadLocalRandom gives better performance and less overhead in a multi-threaded environment. ("Gaussian random value: "+random.nextGaussian()) ("Boolean random value: "+random.nextBoolean()) ("Double random value: "+random.nextDouble()) ("Float random value: "+random.nextFloat())

("Long random value: "+random.nextLong())

In order to generate a random value all you need to do is create an instance for the Random class and call one of the generator methods nextInt(), nextLong(), nextDouble(), nextFloat(), nextBoolean() or nextGaussian(). The Random class can generate a random number of any type such as int, long, float, double and boolean. Every run generates different random within the range.

Math class of java.util package can be used to generate random number, this method returns double type random numbers in the range 0.0 (included) to 1.0 (not included). Random number can be generated using the below built-in ways provided by Java.Ħ.
