Does anyone know how to generate random numbers every minute?
Right now I only have a for loop where it sends 3 pieces of data, nothing more, but it sends them instantly, and I need it to return a random number every minute.
for(int i =0; i<3; i++){
int numero = (int) (Math.random() * 100) + 1;
System.out.println(numero);
}
Result is:
56
32
49
BUILD SUCCESSFUL (total time: 0 seconds)
You can use a call to to introduce a millisecond
Thread.sleep()
wait before getting the next number.n
Sleep
receives the number of milliseconds that the calling thread will sleep before continuing its execution.Example, adapting your code, it could be:
The output will be the same, but your program will deliver each number 1 minute after the previous one.
One flaw in the code I'm sending you is that after delivering the last number, the program will wait a minute before exiting. This is not necessary, it remains as an exercise for you to adapt it so that it does not make that wait, if you wish.