Java ThreadLocalRandom ints() methodThe ints() method of Java ThreadLocalRandom class returns an effectively unlimited stream of pseudorandom int values. This method overrides ints in class Random. Syntax:Parameter:NA Returns:This method returns a stream of pseudorandom int values. Example 1Output: stream of pseudorandom int value is: java.util.stream.IntPipeline$Head@136432db Java ThreadLocalRandom ints(long streamSize) methodThe ints(long streamSize) method of Java ThreadLocalRandom class returns a stream producing the given streamSize number of pseudorandom int values. This method overrides ints in class Random. Syntax:Parameter:streamSize - It is the number of values to generate Returns:This method returns a stream of int values. Exception:IllegalArgumentException: This exception will throw if streamSize is less than zero. Example 1Output: stream of int value is: java.util.stream.IntPipeline$Head@7382f612 Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: size must be non-negative at java.base/java.util.concurrent.ThreadLocalRandom.ints(Unknown Source) at tests.ThreadLocalRandomIntsExample2.main(ThreadLocalRandomIntsExample2.java:7) Java ThreadLocalRandom ints(int randomNumberOrigin, int randomNumberBound) methodThe ints(int randomNumberOrigin, int randomNumberBound) method of Java ThreadLocalRandom class returns an effectively unlimited stream of pseudorandom int values. Each value must conform to the given origin (inclusive) and bound (exclusive). This method overrides ints in class Random. Syntax:Parameter:randomNumberOrigin: It is the origin (inclusive) of each random value. randomNumberBound: It is the bound (exclusive) of each random value. Returns:This method returns a stream of pseudorandom int values. Exception:IllegalArgumentException: This exception will throw if randomNumberOrigin is greater than or equal to randomNumberBound. Example 1Output: stream of pseudorandom int value is: java.util.stream.IntPipeline$Head@7382f612 Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: bound must be greater than origin at java.base/java.util.concurrent.ThreadLocalRandom.ints(Unknown Source) at tests.ThreadLocalRandomIntsExample2.main(ThreadLocalRandomIntsExample2.java:7) Java ThreadLocalRandom ints(long streamSize, int randomNumberOrigin, int randomNumberBound) methodThe ints(long streamSize, int randomNumberOrigin, int randomNumberBound) method of Java ThreadLocalRandom class returns a stream producing the given streamSize number of pseudorandom int values. Each value must conform to the given origin (inclusive) and bound (exclusive). This method overrides ints in class Random. Syntax:Parameter:streamSize - It is the number of values to generate randomNumberOrigin - It is the origin (inclusive) of each random value randomNumberBound - It is the bound (exclusive) of each random value Returns:This method returns a stream of pseudorandom int values. Exception:
Example 1Output: stream of pseudorandom int value is: java.util.stream.IntPipeline$Head@7382f612 Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: size must be non-negative at java.base/java.util.concurrent.ThreadLocalRandom.ints(Unknown Source) at tests.ThreadLocalRandomIntsExample2.main(ThreadLocalRandomIntsExample2.java:7) Next TopicJava-threadlocalrandom-longs-method |