1

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

  • 1
    @cfrick Not a duplicate. that is Java this is using Groovy script – Humanid 1652487954543 Nov 06 '17 at 18:13
  • Minus syntax differences, any Java solution is usually a Groovy solution -- it might not be the shortest one. Have you tried the most upvoted soltion from that question with Groovy? `java.util.concurrent.ThreadLocalRandom.current().nextInt(10000,90000)` – cfrick Nov 06 '17 at 19:49

1 Answers1

1

I found my error: I just needed to switch the 90000 and the 10000 for 1. Correct code:

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