Forum Discussion

JimLin's avatar
JimLin
Occasional Contributor
12 years ago

RandomStringUtils.random variation locks up soapui

Hi,

I have a small script for generating a random 3 digit numeric/alphanumeric string which works without issue:

import org.apache.commons.lang.RandomStringUtils

//Random 3 digit string
String randomString = (RandomStringUtils.random(3, false, true))

The 'false/true' above sets numbers and/or letters.

I now need one that generate a random 3 digit string, but between specific limits, i.e. starting at 1 and finishing at 193. Looking at this page http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/RandomStringUtils.html, this variation seems to fit the bill 'RandomStringUtils.random(int, int, int, boolean, boolean)' - which represents ' - 'int count, int start, int end, boolean letters, boolean numbers', however, when I add in the start and end integers, soapui locks up and the only thing to do is kill it in task manager. This happens when used in a Groovy step in a test or via the Groovy console.

Does anyone have any suggestion as to what it causing the issue. It's a tiny script, so I'm surprised it causes me such issues.
  • JimLin's avatar
    JimLin
    Occasional Contributor
    Hi SiKing, thanks for your reply and the new link. Where is the info about what versions are used, on the Codehaus or SmartBear website?

    Possibly because I've not had enough coffee yet, but your answer doesn't make it any clearer. I would be grateful if you could you kindly provide an example, thanks.

    Regards,
    JimLin
  • SiKing's avatar
    SiKing
    Community Expert
    JimLin wrote:
    Where is the info about what versions are used, on the Codehaus or SmartBear website?

    Look in $SOAPUI_HOME/lib.
    JimLin wrote:
    Possibly because I've not had enough coffee yet, but your answer doesn't make it any clearer. I would be grateful if you could you kindly provide an example, thanks.

    RandomStringUtils picks characters from a character array. In other words, there are no "numbers", there are only characters that might look like numbers.
    The random(int, int, int, boolean, boolean) method is awkward to use and not going to do what you want. You will need to use something like:
    def rnd = new Random()
    def randomNumber = rnd.nextInt(193) + 1
    def randomString = randomNumber.toString().padLeft(3, "0")
  • JimLin's avatar
    JimLin
    Occasional Contributor
    Hi SiKing,

    With your script I have now got my problem sorted. Thank you very much for your assistance.

    Regards,
    James