Jmeter - weighted random values?

前端 未结 4 605
执念已碎
执念已碎 2021-01-14 00:32

How can I go about running tests/controllers based on random weight? For instance, have two tests, one with a weight of 25%, the other with 50%. The one with 50 should run t

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-14 01:16

    I achieved this by creating a Switch Controller with the following switch value:

    ${__javaScript( var s="001"; new Number(s.charAt( Math.floor(Math.random()*s.length) )) )}
    

    The javascript selects a random character from the string s and converts it to a number. So in the example above, 0 would be selected twice as often as 1, and the weightings can be altered by adding/removing characters from the string.

    I used a String and not an Array was because the javascript version used by my version of JMeter appeared to not support array literals, so this made it a bit less verbose.

提交回复
热议问题