'How to generate numbers in order from 1 to 10000 in groovy?
I need to parameterize the script so that the numbers are used in order
Solution 1:[1]
You can use the range syntax to generate an array of in order numbers.
def countParam = 10000
?def range = 1..countParam
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]
Solution 2:[2]
The answer will depend on your requirements, i.e. in what form and how you're going to use these numbers further.
Once of the possible options is using upto()
function:
If you want comma-separated values for later storing in JMeter Variable you can use a StringBuilder instance like:
def numbers = new StringBuilder()
1.upto(1000) {
numbers.append(it)
if (it < 1000) {
numbers.append(',')
}
}
vars.put('numbers', numbers)
you will get:
1,2,3,4,5,6,7,8,9,10....1000
You may find The Groovy Templates Cheat Sheet for JMeter article useful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kobey |
Solution 2 | Dmitri T |