Reputation: 2285
I heard of some Math.random()
but I'm not sure about using it correctly. Number must be whole, so I suppose I'll need some rounding function.
Upvotes: 0
Views: 2554
Reputation: 3907
Math.random() returns a number between 0 - 1. Multiply it with 10 an round it using an int.
// random number between 1- 10
var randomRounded : int = Math.round(Math.random() * 10);
Edit: more accurate version
// more accurate
var randomRounded : int = Math.floor(Math.random() * 11);
Upvotes: 0
Reputation: 4583
Math.random produces a pseudo random number between [0;1[ (0 included, but 1 excluded) To have an evenly distributed probability for all numbers between 0 and 10, you need to:
var a : int = Math.floor( Math.random() * 11 )
Upvotes: 3