lundi 17 avril 2023

How to generate random number from between max and min

For instance max = 50 and min = 1 I want to find a random number from 48 to 5 what would the code be?

I wrote the part on how to find a random number from a smaller no. To a larger one.

Int r = nextInt(max - min + 1) + min

But I’m confused as to how to do it the other way around

I tried substituting and adding the max min around but the result I want did not appear




Aucun commentaire:

Enregistrer un commentaire