## Forum Discussion

sonya_m
SmartBear Alumni (Retired)
5 years ago

# [TechCorner Challenge #9] Generate a random number within a range

Hi Community!   Another awesome task is readyðŸ™‚   By completing the task, you will not only learn TestComplete features but also get into the TechCorner Leaderboard.   Participate in the ...
• 5 years ago

Task: Generate a random number within the following range (30-75) in TestComplete using a scripting language of your choice.

This is a solution created for [TechCorner Challenge #9]

I used math random() method in javascript to do that, let me try to do it in another language as well.

``````//JavaScript
//JScript

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

function getRandomNumber(min, max)

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

• 5 years ago

Task: Generate a random number within the following range (30-75) in TestComplete using a scripting language of your choice.

This is a solution created for [TechCorner Challenge #9]

The following Vb Script code demonstrates how to generate random integers that fall within a specified range from 30 to 75. Here, I have used 'Rnd' function

``````'VBScript

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

• 5 years ago

Task: Generate a random number within the following range (30-75) in TestComplete using a scripting language of your choice.

This is a solution created for [TechCorner Challenge #9]

Hi folks, I gather you just want to have the value returned, not actually automate input of that value into an application?

If so, here's some Python.

``````#python

from random import randrange

Log.Message(randrange(30, 75, 1))``````