Forum Discussion

sonya_m's avatar
sonya_m
SmartBear Alumni (Retired)
4 years ago
Solved

[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 ...
  • anupamchampati's avatar
    4 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;
    }

     

     

  • mkambham's avatar
    4 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

     

     

     

     

  • Wrongtown's avatar
    4 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))