问题描述
我需要为邮递员生成特定范围内的随机数.从我在 邮递员网站是:
I need to generate random number in specific range for postman.I wonder if there is possible to generate it and to use it in variable in postman, from what I saw at postman site is:
{{$randomint }}
将给出 1-1000 之间的随机数我已经尝试过这样做:
will give random number between 1-1000and I already tried to do something like this:
{{$randomint(1,5)}}
获取1-5之间的数字但是邮递员没有这种选项,那么邮递员如何指定随机数的范围?
to get number between 1-5 but postman didn't get this kind of option, so how to specify range for the random in postman?
推荐答案
你可以只使用 Lodash
因为它是一个内置的 模块:
You can just use Lodash
for this as it's a built-in module:
pm.environment.set("random_number", _.random(1, 5))
或者只是将数字 5
添加到 _.random()
函数中,这将是一个从 0 到 5 的数字.
Or just add the number 5
to the _.random()
function and this will be a number from 0 to 5.
这篇关于邮递员 - 如何生成特定范围内的随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!