I want a groovy simple code that generates Random number
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018
10:53 AM
07-05-2018
10:53 AM
I want a groovy simple code that generates Random number
I want a groovy simple code that generates Random number, and i don't want to add random number generator
Currently i am using:
import org.apache.commons.lang.RandomStringUtils log.info getRandomNumber(8) def getRandomNumber(int num) { String charset = (('1'..'9')).join() def randValue = RandomStringUtils.random(num, charset) while (randValue.size()!=num) { randValue = RandomStringUtils.random(num, charset) } return randValue }
Any alternate or better solution for this?
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
Thanks and Regards,
Himanshu Tayal
2 REPLIES 2
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018
11:20 AM
07-05-2018
11:20 AM
Short of using the built in libraries, you have a decent enough solution. Any other solution I could think of is just a variation of what you already have.
---
Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018
12:35 PM
07-05-2018
12:35 PM
Thanks for the reply @groovyguy
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
Thanks and Regards,
Himanshu Tayal
