Yes, Math.random()
is an excellent way to accomplish this. What you want to do is compute a single random number, and then make decisions based on that:
var d = Math.random();
if (d < 0.5)
// 50% chance of being here
else if (d < 0.7)
// 20% chance of being here
else
// 30% chance of being here
That way you don't miss any possibilities.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…