Forum Discussion

CByler's avatar
CByler
Contributor
9 years ago

Newb Question: REST Insert Random Number

I have searched both here and via google trying to find the best way to generate random numbers in test cases.  I have attempted to work with strings such as the below:   ${=(int)(Math.random()*999...
  • nmrao's avatar
    9 years ago

     

    Random number between the range

     

    Math.abs(new Random().nextInt() % max + min)

    So, in your case - Math.abs(new Random().nextInt() % 17 + 3)

     

    You may have goovy script

    context.testCase.testSuite.project.setPropertyValue("ACCOUNT_NUMBER", (Math.abs(new Random().nextInt() % 17 + 3).toString())

    And you need to use ${#Project#ACCOUNT_NUMBER} where that is needed.

     

    Just thinking of the number to tests to make the changes like you mentioned, you may alternatively look at Events - FilterRequest to modify the request with the changes need to avoid bulk changes for each test case if possible. Currently can't say much as do not know about the data variations.