JS Math.random()复制以前的值

时间:2015-02-02 12:26:51

标签: javascript

我试图为网页浏览器制作一个滑冰骰子,但几乎每次我得到相同的结果,即使页面已被刷新以使该功能再次运行。

<script>
function closeit()
{
document.getElementById("popup").style.display ="none";
}

function reload()
{
window.location.reload(),
setTimeout(10000);
}
var rolldie1 = Math.random();

if (rolldie1 <= 0.50)
  {
    answer1 = "";
    document.getElementbyId("popup").textContent ="";
  } else if (rolldie1 <= 0.60)
  {
    answer1 = "Switch";
    document.getElementbyId("popup").textContent ="Switch";
  } else if (rolldie1 <= 0.65)
    {
      answer1 ="Nollie";
      document.getElementbyId("popup").textContent ="Nollie";
    }
 else if (rolldie1 <= 0.75)
    {
      answer1 ="Fakie";
      document.getElementbyId("popup").textContent ="Fakie";
    }
 else if (rolldie1 <= 0.90)
    {
      answer1 ="Frontside";
      document.getElementbyId("popup").textContent ="Frontside";
    }
 else if (rolldie1 <= 0.99)
    {
      answer1 ="Backside";
      document.getElementbyId("popup").textContent ="Backside";
    }
  else if (rolldie1 <= 0.50)
    {
      answer1 ="";
      document.getElementbyId("popup").textContent ="";
    }
function show1()
{
  var elem = document.getElementById("popup");
    elem.style.display = "block";

    document.getElementById("popup");
}

function sa1()
{
sa2();
sa3();
sa4();
document.getElementById("a1").textContent = answer1;
}
</script>
<script>
function reload()
{
window.location.reload(),
setTimeout(10000);
}

var rolldie2 = Math.random(), answer2; 

if (rolldie2 <= 0.30)
  {
    answer2 = "Kickflip";
    document.getElementbyId("popup").textContent ="Kickflip";
  } else if (rolldie2 <= 0.40)
    {
      answer2 ="Heelflip";
      document.getElementbyId("popup").textContent ="Heelflip";
    }
 else if (rolldie1 <= 0.60)
    {
      answer2 ="";
      document.getElementbyId("popup").textContent ="";
    }
 else if (rolldie2 <= 0.90)
    {
      answer2 ="Pop Shove";
      document.getElementbyId("popup").textContent ="Pop Shove";
    }
 else if (rolldie1 <= 0.94)
    {
      answer2 ="360 Flip";
      document.getElementbyId("popup").textContent ="360 Flip";
    }
 else if (rolldie1 <= 0.99)
    {
      answer2 ="Varial";
      document.getElementbyId("popup").textContent ="Varial";
    }
function show1()
{
  var elem = document.getElementById("popup");
    elem.style.display = "block";

    document.getElementById("popup");
}

function sa2()
{
document.getElementById("a2").textContent = answer2;
}
</script>
<script>
function reload()
{
window.location.reload(),
setTimeout(10000);
}

var rolldie3 = Math.random(), answer3; 

if (rolldie3 <= 0.16)
  {
    answer3 = "";
    document.getElementbyId("popup").textContent ="";
  } else if (rolldie1 <= 0.60)
        {
          answer3 ="360";
          document.getElementbyId("popup").textContent ="360";
         }
     else if (rolldie3 <= 0.95)
         {
          answer3 ="540";
          document.getElementbyId("popup").textContent ="540";
        }
 else if (rolldie3 <= 0.97)
    {
      answer3 ="720";
      document.getElementbyId("popup").textContent ="720";
    }
 else if (rolldie3 <= 0.99)
    {
      answer3 ="900";
      document.getElementbyId("popup").textContent ="900";
    }
 else if (rolldie3 <= 0.90)
    {
      answer3 ="180";
      document.getElementbyId("popup").textContent ="180";
    }
function show1()
{
  var elem = document.getElementById("popup");
    elem.style.display = "block";

    document.getElementById("popup");
}

function sa3()
{
document.getElementById("a3").textContent = answer3;
}
</script>
<script>
function reload()
{
window.location.reload(),
setTimeout(10000);
}

var rolldie4 = Math.random(), answer4; 

if (rolldie4 <= 0.90)
  {
    answer4 = "Nose Manual";
    document.getElementbyId("popup").textContent ="Nose Manual";
  } else if (rolldie4 <= 0.60)
    {
      answer4 ="";
      document.getElementbyId("popup").textContent ="";
    }
 else if (rolldie4 <= 0.80)
    {
      answer4 ="Manual";
      document.getElementbyId("popup").textContent ="Manual";
    }
 else if (rolldie4 <= 0.85)
    {
      answer4 ="Nollie Pivot";
      document.getElementbyId("popup").textContent ="Nollie Pivot";
    }
 else if (rolldie4 <= 0.95)
    {
      answer4 ="Sexchange";
      document.getElementbyId("popup").textContent ="Sexchange";
    }
 else if (rolldie4 <= 0.99)
    {
      answer4 ="Cross Foot";
      document.getElementbyId("popup").textContent ="Cross Foot";
    }
function show4()
{
  var elem = document.getElementById("popup");
    elem.style.display = "block";

    document.getElementById("popup");
}

function sa4()
{
document.getElementById("a4").textContent = answer4;
}
</script>

这是我尝试过的。非常感谢任何帮助,提前谢谢。

0 个答案:

没有答案