vendredi 29 janvier 2016

java random number with "variable Max/Min"

So stop me if you've heard this one. I've already looked all over this and other forums to see if anyone had tried this, and I can't find it for the life of me.

I'm trying to generate a random number, but the Max/Min are variables. The values are derived from a text file and can be changed at will by the user.

Is there a way to make a single rn.nextInt such that the Max/Min could be both negative, both positive, one positive and one negative, or the same number (including both being 0)?

The purpose is to have a setting in my game where the user can choose a markup value on purchasable items, but I want to allow discounts as well. I also want them to have the option to set both values to 0 and just use the stock value of the items.

I have tried a few workarounds already, including:

//for Max = 0, Min = 0
int n = (rn.nextInt((a) + (b + 1000))) - 1000

which I really hoped would work.

Any help would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire