Languages
[Edit]
EN

Java - 4 different ways to generate random double in range

10 points
Created by:
Xitiz
2195

1. Generate random double in range with ThreadLocalRandom

Edit

Example:


2. Generate random double in range with Random class

Edit

Example:


3. Generate random double in range with Random and DoubleStream

Edit

Example:


4. Generate random double in range with Math

Edit

Example:


5. Test if double in range methods work as expected

Edit

Output (only first 5 x doubles and last 5 x doubles):


References

Edit

ThreadLocalRandom - Java docs
Math - Java docs
Random - Java docs
DoubleStream - Java docs

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - random numbers

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join