mercredi 16 septembre 2015

Is it possible to generate random negative number range in Java?

I have seen MANY posts on here in regard to generating random numbers with a specific range in JAVA (especially this one). However, I have not found one that describes how to generate a random number between a negative MAX and a negative MIN. Is this possible in Java?

For example, if I want to generate a random number that is between (-20) and (-10). Using something like the below will only result in a JAVA Exception that screams about n having to be positive:

int magicNumber=(random.nextInt(-20)-10);




Aucun commentaire:

Enregistrer un commentaire