function calcuate() { var roles = document.getElementById("roles").value.split("\n").removeAll(""); var players = document.getElementById("players").value.split("\n").removeAll(""); if (roles.length == players.length) { document.getElementById("result").value = ""; var count = roles.length; for (var i = 0; i < count; i++) { // Math.random range[0,1) // Math.random() * players.length range [0, length) // Math.floor(Math.random() * players.length) range [0, 1, 2, ... range-1] var player = players[Math.floor(Math.random() * players.length)]; var role = roles[i]; players.remove(player); document.getElementById("result").value += player + " ---------- " + role + " \n"; } } else { document.getElementById("result").value = "角色与身份数量不符。" }}
var a=0;var b=10000000;for (var i =0;i<b;i++) {a += Math.random()*7;}console.log(a/b)VM307:6 3.5001398964456847