Knowledge Base Article

Generate a random number within a range


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.



Solution given by anupamchampati 


function test()

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


Solution given by mkambham 


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


Solution given by Wrongtown 


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