Java random class: generate random numbers - how it works
In this practical tip, we will show you how to correctly import and use the random class in Java.
Java random class: generate random numbers - how it works
If you are not yet familiar with Java, you can first read our basics here.
- First import the package with the command »import java.util.concurrent.ThreadLocalRandom;«.
- Now you can create a random number with the command "int randomNum = ThreadLocalRandom.current (). NextInt (min, max + 1);".
- The number is saved as an integer.
In the next article we will show you how to properly create and use arrays in Java.