There are basically many methods to generate random numbers in QTP. Major among them are using loops or creating two loops and concat it. But these methods has limitations of generating numbers in a particular range and if we want unique number on daily basis this methods fails. We need to alter the scripts on daily basis. We can also use Randomize() function given by QTP but again there is no surity that all the numbers generated by them are unique.
So here we can do the following things :
1) Use Randomize function and concanete it with timestamp , it will be unique
Randomize
iTmp = Int((sMaxVal * Rnd) + 1)
2) Use date time and second methods and concanete it. It will always generate a random number
Dim sDate : sDate = Day(Now)
Dim sMonth : sMonth = Month(Now)
Dim sYear : sYear = Year(Now)
Dim sHour : sHour = Hour(Now)
Dim sMinute : sMinute = Minute(Now)
Dim sSecond : sSecond = Second(Now)
Int(sDate & sMonth & sYear & sHour & sMinute & sSecond)
So here we can do the following things :
1) Use Randomize function and concanete it with timestamp , it will be unique
Randomize
iTmp = Int((sMaxVal * Rnd) + 1)
2) Use date time and second methods and concanete it. It will always generate a random number
Dim sDate : sDate = Day(Now)
Dim sMonth : sMonth = Month(Now)
Dim sYear : sYear = Year(Now)
Dim sHour : sHour = Hour(Now)
Dim sMinute : sMinute = Minute(Now)
Dim sSecond : sSecond = Second(Now)
Int(sDate & sMonth & sYear & sHour & sMinute & sSecond)
No comments:
Post a Comment