Some type of "Math.random()" command?
Is it possible to have some sort of
math.random()
command with Titanium? Or something like that? (Where it randomly chooses between values you set).
I need it to choose a number between 1 and 5 and then have it do what I want for each. I know Lua and PHP have this, but I don't know if JavaScript does (Or if Titanium, rather).
2 Answers
-
As the example above shows, the most common way is:
randomnumber = Math.floor(Math.random() * (highestNumberWanted + 1));
Another commonly used method is:
randomnumber = new Date().getTime() % (highestNumberWanted + 1);
-
http://www.w3schools.com/js/js_obj_math.asp