Knowledge Base Article

Generate a random number within a range

Question

How to generate a random number within the following range (30-75) in TestComplete? The article was created based on the TechCornerChallenge event with answers given by different community members.

 

Answer

Solution given by anupamchampati 

//JavaScript
//JScript

function test()
{
 Log.Message(getRandomNumber(30,75))
}

function getRandomNumber(min, max)
{
  return Math.floor(Math.random() * (max - min + 1) ) + min;
}

 

Solution given by mkambham 

'VBScript

Function RandomNumber_In_givenRange()
  Dim Minimum
  Dim Maximum
  Minimum = 30
  Maximum = 75
  Randomize
  Log.Message Int((Maximum - Minimum + 1) * Rnd + Minimum)
End Function

 

Solution given by Wrongtown 

#python

from random import randrange

Log.Message(randrange(30, 75, 1))
Published 3 years ago
Version 1.0

Was this article helpful?

No CommentsBe the first to comment