var n=6;
alert(Math.floor(Math.random()*(n+1)))  //1~6

解决方案 »

  1.   

    var a=parseInt(Math.random()*6);
    var b=parseInt(Math.random()*6);
    document.write("<input type=\"button\" value=\"button\" onclick=\"fun();\"/>");
    function fun()
    {
    document.write("<table border=\"1\">");
    document.write("<tr>");
    document.write("<td>"+a+"</td>"+"<td>"+b+"</td>");
    document.write("</table>");
    }
      

  2.   

    random返回的数可能为0但总是小于1
    所以
    function Random(min,max)
    {
        return Math.floor(Math.random()*max) + min;
    }
    才对