Wednesday, 7 August 2013

How to generate a random number in corona SDK

We can use math.random() for the purpose of generating random numbers in corona SDK.
There are 3 main types for this call. They are:

1) Witout any argument:
        math.random()
        -- This will return a pseudo random number in the range of [0,1)
   
2) With one argument:
        math.random(a)
        -- This will return a pseudo random number in the range of [0,a]
   
        eg: print(math.random(5))  ----> return a number between 1 and 5 (both inclusive)
   
3) With two arguments:
        math.random(a,b)
        -- This will return a pseudo random number in the range of [a,b]
   
        eg: print(math.random(2,10))  ----> return a number between 2 and 10 (both inclusive)

No comments:

Post a Comment