How to generate random positive and negative numbers in Java
public static int generatRandomPositiveNegitiveValue(int max , int min) {
//Random rand = new Random();
int ii = -min + (int) (Math.random() * ((max - (-min)) + 1));
return ii;
}
Random random=new Random();
int randomNumber=(random.nextInt(65536)-32768);
You random on (0, 32767+32768)
then subtract by 32768
Generate numbers between 0 and 65535 then just subtract 32768