<html><script language="javascript"> function calc() { var p1 = document.getElementById('prob1'); var p2 = document.getElementById('prob2'); var sample = parseInt(document.getElementById('sample').value); var cnt1 = 0, cnt2 = 0; var prize, choice; for (var i = 0; i < sample; i++) { prize = Math.floor(Math.random() * 3 + 1); choice = Math.floor(Math.random() * 3 + 1); if (prize === choice) cnt1++; else cnt2++; } p1.value = cnt1; p2.value = cnt2; }</script> 样本<input id="sample" value="10000" /><br /> 不换<input id="prob1" /><br /> 换<input id="prob2" /><br /> <input type="button" value="计算" onclick="javascript:calc();"/></body></html>
计算结果换的几率差不多是2/3