Forum Discussion

Artyom's avatar
Artyom
Occasional Contributor
14 years ago

Random function for Jscript

Please, put an example of using Random function in TC with JScript.

I use default call like

i=Math.Random()

but TC produces an error in this case.

Also are there any other random or randomize functions for TC which can be used with JScript?

Thank you.

4 Replies


  • Hi Artyom,





    I would like to add some information.







    Also are there any other random or randomize functions for TC which can be used with JScript?



    No, there are not. The random method of the Math object in Microsoft JScript generates a different value every time it is called, so there is no need in randomizing. Also, you can use the random method of the standard Microsoft JScript Math object in the following way to generate numbers outside the interval between 0 and 1:







      Log.Message(Math.random()); // from 0 (inclusive) to 1 (exclusive)

      Log.Message(Math.round(Math.random()*100)); // from 0 (inclusive) to 100 (exclusive)

      Log.Message(Math.round(Math.random()*50)); // from 0 (inclusive) to 50 (exclusive)







    Please see the following MSDN Library article for additional information regarding the Math object.


  • Artyom's avatar
    Artyom
    Occasional Contributor
    Thanks, Allen. Actually I do like that. Anyway this is useful info:)