QA automation with QTP/UFT – a simple function to random numbers based on your provided length

Hello. I've received a lot of requests for this tutorial. The function I am about to show, can be used for a variety of different testing purposes. One example is if you need to generate a random password for testing sign up users. The function is very simple. The code is below:

Function fun_getRandomNumbers(intTotalNumbers)
 Dim i
 For i = 1 To intTotalNumbers
 'Returns an ASCII character 49-57 = digits 1-9
 fn_getRandomNumbers = fn_getRandomNumbers & Chr(Int((57 - 49 + 1) * Rnd + 49))
End Function


To call this function, just type the function name and specify the fixed length of the random number. See example below:

MsgBox fun_getRandomNumbers(10)

Awesome! You did it! Leave your comments and feedback below. I love hearing what you have to say 🙂

Pin It on Pinterest

Clef two-factor authentication