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
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.
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 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).
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)
})
To use this in the main request, you can use the {{phoneNumber}}
syntax to add this to the URL or the request body.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With