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 challenge and earn new unique badges! Check out some of these awesome rewards:
Let's imagine that you are testing an application that has gaming elements - a knight is using a legendary sword to slay a dragon! And, the sword will deliver damage in the following range - from 30 to 75.
Instead of using the same number every time, you want to generate a random number on each run and enter it in the application. How would you do it in TestComplete?
Let's see if we can get an example for each scripting language (JavaScript, JScript, Python, VBScript)!
Task: Generate a random number within the following range (30-75) in TestComplete using a scripting language of your choice.
Difficulty:
Bonus: You will get an additional point for each script written in a different language.
Best of luck!
Solved! Go to Solution.
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;
}
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
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))
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;
}
@anupamchampati Awesome! Thank you for participation!
JavaScript is done🙂 Which other language would you like to try doing this task for?
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
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))
@mkambham @Wrongtown great job! Your scripts work like magic.
Looks like only JScript is left! Will you give it a try?🙂
@anupamchampati Thank you for checking that this works for JScript, too! A Bonus Point for this task is yours🙂
Same Script for JScript and JavaScript
the Code is below.
function RandomNumber_between_Range()
{
var min = 30;
var max = 75;
RandomNumber = Math.floor(Math.random()*(max-min+1)+min);
Log.Message(RandomNumber)
}
Great job.
Subject | Author | Latest Post |
---|---|---|