I executed this bunch of code:
int newOrderLow = ThreadLocalRandom.current().nextInt(50, shipCapacity / 3);
int newOrderUp = ThreadLocalRandom.current().nextInt(newOrderLow, shipCapacity + 1); // not lower than lower value
int newOrderMid = ThreadLocalRandom.current().nextInt(newOrderLow, newOrderUp + 1); // in between
Log.d(TAG, "New Order: {" + newOrderLow + ", " + newOrderMid + ", " + newOrderUp + "}");
and started debugging it. For example, when I set shipCapacity as 600, I got these figures logged in my console:
New Order: {493, 772, 672}
One thing is that upper range is not within [lower value; shipCapacity + 1], the other one is the middle value result. So what is the issue? How to generate random integers properly using ThreadLocalRandom?
Aucun commentaire:
Enregistrer un commentaire