I have an array with two items and I need to random a choice of this items but the most of times I get the same item from array...
See the code:
var
The Math.random()
function returns a floating-point, pseudo-random number in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range.
Math.random() * 2
will give range 0 to 1.99999999999999 but not 2. Math.floor(0...1.999999999999)
will either return 0 or 1 with 50% chance similar to a coin.
numbers[0
] will give 523 and numbers[1]
will give 3452