邮递员-如何生成特定范围内的随机数? [英] postman - how to generate random number in specific range?

查看:107
本文介绍了邮递员-如何生成特定范围内的随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为邮递员生成特定范围内的随机数。
我想知道是否有可能生成它并将其用于邮递员的变量中,从我在邮递员站点为:

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-1000 and 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.

这篇关于邮递员-如何生成特定范围内的随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆