在發送請求的時候,我們需要用到隨機數,例如:請求的參數是隨機的郵箱,隨機的字符,隨機的圖片等...那這種情況,我們如何做到隨機生成值呢?哈哈哈哈,postman內置了一些隨機變量。
接下來分爲兩部分,第一部分:隨機變量有哪些。第二部分:如何使用。
第一部分:官方文檔:https://learning.getpostman.com/docs/postman/variables-and-environments/variables-list/
針對裏面隨機變量的中文解釋(哈哈哈哈哈....)以下文檔從簡書中某位大佬中摘取。
隨機唯一性字符串
這些是唯一性很強的字符串,對於一些有唯一限制的內容可以使用這些值來填充。
Variable Name |
Description |
Examples |
---|
$guid |
uuid-v4 風格的 guid,隨機性非常強 |
"611c2e81-2ccb-42d8-9ddc-2d0bfa65c1b4" |
|
|
"3a721b7f-7dc9-4c45-9777-516942b98e0d" |
|
|
"22eca807-006b-47df-9511-e92e37f5071a" |
$timestamp |
時間戳 |
1562757107 , 1562757108 , 1562757109 |
$randomUUID |
隨機 36 位的 UUID |
"6929bb52-3ab2-448a-9796-d6480ecad36b" |
|
|
"53151b27-034f-45a0-9f0a-d7b6075b67d0" |
隨機文字、字符串、顏色(碼)
Variable Name |
Decription |
Examples |
---|
$randomAlphaNumeric |
1位隨機字符或數字 |
6 , "y" , "z" |
$randomBoolean |
隨機布爾值 (true/false) |
true , false , false , true |
$randomInt |
1~1000 之間的隨機整數 |
802 , 494 , 200 |
$randomColor |
隨機顏色單詞 |
"red" , "fuchsia" , "grey" |
$randomHexColor |
隨機顏色碼 |
"#47594a" , "#431e48" , "#106f21" |
$randomAbbreviation |
隨機縮寫 |
SQL , PCI , JSON |
隨機網絡標識和 IP 地址
Variable Name |
Decription |
Examples |
---|
$randomIP |
隨機的 IPv4 地址 |
241.102.234.100 , 216.7.27.38 |
$randomIPV6 |
隨機 IPv6 地址 |
dbe2:7ae6:119b:c161:1560:6dda:3a9b:90a9 |
|
|
c482:23a4:ce4c:a668:7736:6cc5:b0b6:cc37 |
|
|
c791:18d1:fbba:87d8:d929:22aa:5a0a:ac3d |
$randomMACAddress |
隨機 MAC(物理)地址 |
33:d4:68:5f:b4:c7 , 1f:6e:db:3d:ed:fa |
$randomPassword |
由字母和數字組成的 15 位隨機密碼 |
t9iXe7COoDKv8k3 , QAzNFQtvR9cg2rq |
$randomLocale |
隨機兩位字母組成的語言代碼 (ISO 639-1) |
"ny" , "sr" , "si" |
$randomUserAgent |
隨機用戶代理 |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.9.8; rv:15.6) Gecko/20100101 Firefox/15.6.6 |
|
|
Opera/10.27 (Windows NT 5.3; U; AB Presto/2.9.177 Version/10.00) |
|
|
Mozilla/5.0 (Windows NT 6.2; rv:13.5) Gecko/20100101 Firefox/13.5.6 |
$randomProtocol |
隨機協議類型 |
"http" , "https" |
$randomSemver |
由數字組成的隨機版本號 |
7.0.5 , 2.5.8 , 6.4.9 |
隨機姓名(英文)
Variable Name |
Decription |
Examples |
---|
$randomFirstName |
隨機的名字(英文) |
Ethan , Chandler , Megane |
$randomLastName |
隨機姓氏(英文) |
Schaden , Schneider , Willms |
$randomFullName |
隨機全名(名字 姓氏) |
Connie Runolfsdottir , Sylvan Fay , Jonathon Kunze |
$randomNamePrefix |
隨機稱呼 |
Dr. , Ms. , Mr. |
$randomNameSuffix |
隨機姓名後綴 |
I , MD , DDS |
職業
Variable Name |
Decription |
Examples |
---|
$randomJobArea |
隨機工作範圍 |
Mobility , Intranet , Configuration |
$randomJobDescriptor |
隨機職業等級 |
Forward , Corporate , Senior |
$randomJobTitle |
隨機工作標題 |
International Creative Liaison , |
|
|
Product Factors Officer , |
|
|
Future Interactions Executive |
$randomJobType |
隨機工作類型 |
Supervisor , Manager , Coordinator |
隨機電話號碼、區域、地址
Variable Name |
Decription |
Examples |
---|
$randomPhoneNumber |
隨機 10 位數字電話號碼 |
700-008-5275 , 494-261-3424 , 662-302-7817 |
$randomPhoneNumberExt |
隨機擴展號碼(包含區號) |
27-199-983-3864 , 99-841-448-2775 |
$randomCity |
隨機城市名稱 |
Spinkahaven , Korbinburgh , Lefflerport |
$randomStreetName |
隨機街道名稱 |
Kuhic Island , General Street , Kendrick Springs |
$randomStreetAddress |
隨機街道地址 |
5742 Harvey Streets , 47906 Wilmer Orchard |
$randomCountry |
隨機國家名稱 |
Lao People's Democratic Republic , Kazakhstan , Austria |
$randomCountryCode |
隨機兩位字符的國家編碼 (ISO 3166-1 alpha-2) |
CV , MD , TD |
$randomLatitude |
隨機緯度 |
55.2099 , 27.3644 , -84.7514 |
$randomLongitude |
隨機精度 |
40.6609 , 171.7139 , -159.9757 |
隨機圖片
Variable Name |
Decription |
Examples |
---|
$randomImage |
隨機圖片地址 |
http://lorempixel.com/640/480/technics |
|
|
http://lorempixel.com/640/480/food |
|
|
http://lorempixel.com/640/480/business |
$randomAvatarImage |
隨機頭像圖片 |
https://s3.amazonaws.com/uifaces/faces/twitter/johnsmithagency/128.jpg |
|
|
https://s3.amazonaws.com/uifaces/faces/twitter/xadhix/128.jpg |
|
|
https://s3.amazonaws.com/uifaces/faces/twitter/martip07/128.jpg |
$randomImageUrl |
隨機圖片地址 |
http://lorempixel.com/640/480 |
$randomAbstractImage |
隨機頭像縮略圖 |
http://lorempixel.com/640/480/abstract |
$randomAnimalsImage |
隨機動物圖片地址 |
http://lorempixel.com/640/480/animals |
$randomBusinessImage |
隨機股票業務圖片 |
http://lorempixel.com/640/480/business |
$randomCatsImage |
隨機貓圖片 |
http://lorempixel.com/640/480/cats |
$randomCityImage |
隨機城市圖片 |
http://lorempixel.com/640/480/city |
$randomFoodImage |
隨機食物圖片 |
http://lorempixel.com/640/480/food |
$randomNightlifeImage |
隨機夜生活圖片 |
http://lorempixel.com/640/480/nightlife |
$randomFashionImage |
隨機時尚圖片 |
http://lorempixel.com/640/480/fashion |
$randomPeopleImage |
隨機人物圖片 |
http://lorempixel.com/640/480/people |
$randomNatureImage |
隨機自然風景圖片 |
http://lorempixel.com/640/480/nature |
$randomSportsImage |
隨機運動圖片 |
http://lorempixel.com/640/480/sports |
$randomTechnicsImage |
隨機科技圖片 |
http://lorempixel.com/640/480/technics |
$randomTransportImage |
隨機交通工具圖片 |
http://lorempixel.com/640/480/transport |
$randomImageDataUri |
隨機圖片的 data 數據 |
data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22undefined%22%20height%3D%22undefined%22%3E%20%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%20%20%3Ctext%20x%3D%220%22%20y%3D%2220%22%20font-size%3D%2220%22%20text-anchor%3D%22start%22%20fill%3D%22white%22%3Eundefinedxundefined%3C%2Ftext%3E%20%3C%2Fsvg%3E |
隨機金融類數據
Variable Name |
Decription |
Examples |
---|
$randomBankAccount |
隨機的8位數字銀行帳號 |
09454073 , 65653440 , 75728757 |
$randomBankAccountName |
隨機的銀行帳戶名稱(e.g. savings account, checking account) |
Home Loan Account , Checking Account , Auto Loan Account |
$randomCreditCardMask |
隨機屏蔽的信用卡號 |
3622 , 5815 , 6257 |
$randomBankAccountBic |
隨機銀行識別碼 (Bank Identifier Code) |
EZIAUGJ1 , KXCUTVJ1 , DIVIPLL1 |
$randomBankAccountIban |
隨機 15-31位的國際銀行帳號 (International Bank Account Number) |
MU20ZPUN3039684000618086155TKZ |
|
|
BR7580569810060080800805730W2 |
|
|
XK241602002200395017 |
$randomTransactionType |
隨機交易類型 (e.g. invoice, payment, deposit) |
invoice , payment , deposit |
$randomCurrencyCode |
隨機的 3 位字母的貨幣代碼 (ISO-4217) |
CDF , ZMK , GNF |
$randomCurrencyName |
隨機貨幣名稱 |
CFP Franc , Cordoba Oro , Pound Sterling |
$randomCurrencySymbol |
隨機貨幣標誌 |
$ , £ |
$randomBitcoin |
隨機比特幣地址 |
3VB8JGT7Y4Z63U68KGGKDXMLLH5 |
|
|
1GY5TL5NEX3D1EA0TCWPLGVPQF5EAF |
|
|
14IIEXV2AKZAHSCY2KNYP213VRLD |
隨機商業數據
Variable Name |
Decription |
Examples |
---|
$randomCompanyName |
隨機公司名稱 |
Johns - Kassulke , Grady LLC |
$randomCompanySuffix |
隨機公司後綴(e.g. Inc, LLC, Group) |
Inc , LLC , Group |
$randomBs |
隨機商業用語 |
killer leverage schemas , |
|
|
bricks-and-clicks deploy markets , |
|
|
world-class unleash platforms |
$randomBsAdjective |
隨機商業形容詞用語 |
viral , 24/7 , 24/365 |
$randomBsBuzz |
隨機商業流行詞 |
repurpose , harness , transition |
$randomBsNoun |
隨機商業名詞 |
e-services , markets , interfaces |
隨機警句(標語)
Variable Name |
Decription |
Examples |
---|
$randomCatchPhrase |
隨機名言警句 |
Future-proofed heuristic open architecture , |
|
|
Quality-focused executive toolset , |
|
|
Grass-roots real-time definition |
$randomCatchPhraseAdjective |
隨機流行語形容詞 |
Self-enabling , Business-focused , Down-sized |
$randomCatchPhraseDescriptor |
隨機流行描述符號 |
bandwidth-monitored , needs-based , homogeneous |
$randomCatchPhraseNoun |
隨機生成給一個流行名詞 |
secured line , superstructure , installation |
隨機數據庫相關數據
Variable Name |
Decription |
Examples |
---|
$randomDatabaseColumn |
隨機數據庫列名 |
updatedAt , token , group |
$randomDatabaseType |
隨機數據庫類型 |
tinyint , text |
$randomDatabaseCollation |
隨機數據庫排序規則 |
cp1250_bin , utf8_general_ci , cp1250_general_ci |
$randomDatabaseEngine |
隨機數據庫引擎 |
MyISAM , InnoDB , Memory |
隨機日期
Variable Name |
Decription |
Examples |
---|
$randomDateFuture |
隨機未來時間 |
Tue Mar 17 2020 13:11:50 GMT+0530 (India Standard Time) , |
|
|
Fri Sep 20 2019 23:51:18 GMT+0530 (India Standard Time) , |
|
|
Thu Nov 07 2019 19:20:06 GMT+0530 (India Standard Time) |
$randomDatePast |
隨機過去時間 |
Sat Mar 02 2019 09:09:26 GMT+0530 (India Standard Time) , |
|
|
Sat Feb 02 2019 00:12:17 GMT+0530 (India Standard Time) , |
|
|
Thu Jun 13 2019 03:08:43 GMT+0530 (India Standard Time) |
$randomDateRecent |
隨機近期時間 |
Tue Jul 09 2019 23:12:37 GMT+0530 (India Standard Time) , |
|
|
Wed Jul 10 2019 15:27:11 GMT+0530 (India Standard Time) , |
|
|
Wed Jul 10 2019 01:28:31 GMT+0530 (India Standard Time) |
$randomWeekday |
隨機星期幾 |
Thursday , Friday , Monday |
$randomMonth |
隨機月份 |
February , May , January |
隨機域名、電子郵件和用戶名
Variable Name |
Decription |
Examples |
---|
$randomDomainName |
隨機完整域名 |
gracie.biz , armando.biz , trevor.info |
$randomDomainSuffix |
隨機頂級域名 |
org , net , com |
$randomDomainWord |
隨機不合法域名 |
gwen , jaden , donnell |
$randomEmail |
隨機電子郵箱地址 |
[email protected] , [email protected] , [email protected] |
$randomExampleEmail |
隨機電子郵箱地址,域名爲example |
[email protected] , [email protected] , [email protected] |
$randomUserName |
隨機用戶名 |
Jarrell.Gutkowski , Lottie.Smitham24 , Alia99 |
$randomUrl |
隨機 URL 地址 |
https://anais.net , https://tristin.net , http://jakob.name |
隨機文件名和目錄
Variable Name |
Decription |
Examples |
---|
$randomFileName |
隨機文件名 (包括不常用的擴展名) |
neural_sri_lanka_rupee_gloves.gdoc , |
|
|
plastic_awesome_garden.tif , |
|
|
incredible_ivory_agent.lzh |
$randomFileType |
隨機文件類型 (包括不常用的文件類型) |
model , application , video |
$randomFileExt |
隨機文件擴展名 (包括不常見的文件擴展名) |
war , book , fsc |
$randomCommonFileName |
隨機文件名 |
well_modulated.mpg4 , |
|
|
rustic_plastic_tuna.gif , |
|
|
checking_account_end_to_end_robust.wav |
$randomCommonFileType |
隨機常見文件類型 |
application , audio |
$randomCommonFileExt |
隨機常見文件擴展名 |
m2v , wav , png |
$randomFilePath |
隨機文件路徑 |
/home/programming_chicken.cpio , |
|
|
/usr/obj/fresh_bandwidth_monitored_beauty.onetoc , |
|
|
/dev/css_rustic.pm |
$randomDirectoryPath |
隨機目錄路徑 |
/usr/bin , /root , /usr/local/bin |
$randomMimeType |
隨機 MIME 類型(header 中的 content-type 會用到) |
audio/vnd.vmx.cvsd , |
|
|
application/vnd.groove-identity-message , |
|
|
application/vnd.oasis.opendocument.graphics-template |
隨機物料(庫存、商品等)
Variable Name |
Decription |
Examples |
---|
$randomPrice |
隨機生成 100.00 ~ 999.00 之間的價格 |
531.55 , 488.76 , 511.56 |
$randomProduct |
隨機商品 |
Towels , Pizza , Pants |
$randomProductAdjective |
隨機商品形容詞 |
Unbranded , Incredible , Tasty |
$randomProductMaterial |
隨機商品材料 |
Steel , Plastic , Frozen |
$randomProductName |
隨機商品名稱 |
Handmade Concrete Tuna , Refined Rubber Hat |
$randomDepartment |
隨機商業分類 |
Tools , Movies , Electronics |
基於英語語法的隨機數據
Variable Name |
Decription |
Examples |
---|
$randomNoun |
隨機名詞 |
matrix , bus , bandwidth |
$randomVerb |
隨機動詞 |
parse , quantify , navigate |
$randomIngverb |
隨機帶 "-ing" 的動詞 |
synthesizing , navigating , backing up |
$randomAdjective |
隨機形容詞 |
auxiliary , multi-byte , back-end |
$randomWord |
隨機單詞 |
withdrawal , infrastructures , IB |
$randomWords |
一些隨機單詞構成的字符串 |
Samoa Synergistic sticky copying Grocery , |
|
|
Corporate Springs , |
|
|
Christmas Island Ghana Quality |
$randomPhrase |
隨機短語 |
You can't program the monitor without navigating the mobile XML program! , |
|
|
overriding the capacitor won't do anything, we need to compress the optical SMS transmitter! , |
|
|
I'll generate the virtual AI program, that should microchip the RAM monitor! |
隨機的文本內容
Variable Name |
Decription |
Examples |
---|
$randomLoremWord |
隨機單詞 |
est |
$randomLoremWords |
隨機單詞構成的短語 |
vel repellat nobis |
$randomLoremSentence |
隨機單詞構成的句子 |
Molestias consequuntur nisi non quod. |
$randomLoremSentences |
隨機 2~6 條句子構成的段落 |
Et sint voluptas similique iure amet perspiciatis vero sequi atque. Ut porro sit et hic. Neque aspernatur vitae fugiat ut dolore et veritatis. Ab iusto ex delectus animi. Voluptates nisi iusto. Impedit quod quae voluptate qui. |
$randomLoremParagraph |
隨機單詞構成的一段話 |
Ab aliquid odio iste quo voluptas voluptatem dignissimos velit. Recusandae facilis qui commodi ea magnam enim nostrum quia quis. Nihil est suscipit assumenda ut voluptatem sed. Esse ab voluptas odit qui molestiae. Rem est nesciunt est quis ipsam expedita consequuntur. |
$randomLoremParagraphs |
隨機單詞構成的 3 個段落 |
Voluptatem rem magnam aliquam ab id aut quaerat. Placeat provident possimus voluptatibus dicta velit non aut quasi. Mollitia et aliquam expedita sunt dolores nam consequuntur. Nam dolorum delectus ipsam repudiandae et ipsam ut voluptatum totam. Nobis labore labore recusandae ipsam quo. |
|
|
Voluptatem occaecati omnis debitis eum libero. Veniam et cum unde. Nisi facere repudiandae error aperiam expedita optio quae consequatur qui. Vel ut sit aliquid omnis. Est placeat ducimus. Libero voluptatem eius occaecati ad sint voluptatibus laborum provident iure. |
|
|
Autem est sequi ut tenetur omnis enim. Fuga nisi dolor expedita. Ea dolore ut et a nostrum quae ut reprehenderit iste. Numquam optio magnam omnis architecto non. Est cumque laboriosam quibusdam eos voluptatibus velit omnis. Voluptatem officiis nulla omnis ratione excepturi. |
$randomLoremText |
隨機單詞構成的文本 |
Quisquam asperiores exercitationem ut ipsum. Aut eius nesciunt. Et reiciendis aut alias eaque. Nihil amet laboriosam pariatur eligendi. Sunt ullam ut sint natus ducimus. Voluptas harum aspernatur soluta rem nam. |
$randomLoremSlug |
隨機單詞構成的 URL 部分 |
eos-aperiam-accusamus , beatae-id-molestiae , qui-est-repellat |
$randomLoremLines |
由隨機單詞構成的 1~5 行數據(用回車符分隔) |
Ducimus in ut mollitia.\nA itaque non.\nHarum temporibus nihil voluptas.\nIste in sed et |
補充:如果上面的例子不滿足你的要求,你想從某些字符中生成一個字符串。
function getRadomNum(capacity){
//chars中是你要想要的字符的數組
var chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
var res = "";
for(var i = 0; i < capacity ; i ++) {
var id = Math.ceil(Math.random()*chars.length-1);
res += chars[id];
}
return res;
}
//隨機的1-10位數
var name = getRadomNum( Math.ceil(Math.random()*10))
第二部分:使用
在請求時,直接傳{{$randomEmail}} 注意:一定不能有空格,錯誤示範:{{$ randomEmail}}
備註:如果使用動態變量,每次請求都會生成一個新的。
例如:你請求時郵箱是隨機郵箱,然後將郵箱設置爲全局變量後,下次取郵箱,仍然是一個新的隨機郵箱。取不到上述的郵箱。