lundi 6 novembre 2017

How to generate random number within a specific range in groovy script

How do I generate a random number within a specific range in Groovy Script? I want to generate the number between 10,000 and 90,000

Below are my attempts so far:

1.

 Math.abs(new Random().nextInt() % 10000) +90000

2.

(int)(10000 + 90000*Math.random()) 

Both of these generate a random number yes, but they are not within the range of 10,00-90,000




Aucun commentaire:

Enregistrer un commentaire