I have a coding question about how do I generate a random number whose minimum character length is 2 and max is 4. In other words a random number between 10 and 9999
I am aware that we can generate a particular length using RandomStringUtils.randomNumeric(4) but not able to figure out how do I generate a random number between 2 different values
int randomInt = new Random().nextInt(9999 - 10 + 1) + 10
Thanks @Brandon_Hein This works for me.
Before your reply I was able to generate a random number between 10 and 9999 using excel and then calling that cell within the script because I was thinking no body I going to help me today. lol
More generally (for people reading this that want to use different bounds), the algorithm is:
new Random().nextInt(upperBound - lowerBound + 1) + lowerBound
There’s a tip waiting to be written, Brandon…
Or, if you prefer…
“Your mission, should you choose to accept it…”
Plus random strings/words, fixed character set…
Maybe, although a lot of these are already topics in Stack Overflow. Maybe I will aggregate a bunch of these related topics into one tip in the Katalon context, like you mentioned.
You have the Java background, I don’t. It’ll certainly prove a worthy clearinghouse for me.
Here ya go
Thanks for the suggestion.