I am trying to make my own random number generator, but I was constantly getting the same values, I solved this with the sleep function, but how can I do without using sleep please help, I shared my code below.
My Random class
private int x;
private long ms;
public int random(int a) throws InterruptedException
{
ms = System.currentTimeMillis();
x=(int)(ms%a);
Thread.sleep(1);
return (int)x;
}
Main
for(int i=0;i<100;i++)
{
System.out.println(rnd.random(10));
}
Aucun commentaire:
Enregistrer un commentaire