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