Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate random numbers in a range of a phone number format Postman [closed]

I want to generate random numbers in a specific range of numbers. I tried solutions provided in this stackoverflow link but none of the solutions are working. I am able to generate only 1 random number instead of a specific range of numbers. Is there any other solutions I can use to generate a random number for a specific range?

I'm looking for a range of 10 numbers with random numbers. I am looking for a phone number format. For example: (651) 651-6516

like image 506
kav Avatar asked Jun 14 '18 18:06

kav


People also ask

How do you generate random alphanumeric in Postman?

Code for your Pre-request Script tab in Request: function randomString(length=1) { let randomString = ""; for (let i = 0; i < length; i++){ randomString += pm. variables. replaceIn("{{$randomAlphaNumeric}}"); } return randomString; } STRING_LEN = 1000 pm.

Which code block is used to generate a random number?

We can use srand () and rand () function to generate random numbers between 0 and 1. Note that we have to cast the output of rand () function to the decimal value either float or double.

How do you generate a random number in CPP range?

How to Generate Random Numbers in C++ Within a Range. Similar to 1 and 10, you can generate random numbers within any range using the modulus operator. For instance, to generate numbers between 1 and 100, you can write int random = 1+ (rand() % 100).


1 Answers

You use do this in two different ways - You could write some JS code to create random numbers and format it in the way you need or use a 3rd party data generator to do this for you.

By adding this code to the Pre-Request Script you can get the phone data from the randomuser.me API and store this in an environment variable to use in the main request.

pm.sendRequest("https://randomuser.me/api/?nat=us&inc=phone", (err, res) => {
    pm.environment.set('phoneNumber', res.json().results[0].phone)
}) 

Postman Random

To use this in the main request, you can use the {{phoneNumber}} syntax to add this to the URL or the request body.

like image 87
Danny Dainton Avatar answered Oct 03 '22 08:10

Danny Dainton