如何在math.random中不重复数组?

时间:2014-11-03 14:44:20

标签: javascript arrays random

所以我有这个javascript代码,我希望它不重复不同的r_text,所以刷新网站时不会重复r_text []的同一行文本。问题是,代码应该是什么?

<script language="JavaScript">
<!--
var r_text = new Array ();
r_text[0] = "All the leaves are brown";
r_text[1] = "And the sky is grey";
r_text[2] = "I've been for a walk";
r_text[3] = "On a winter's day";
r_text[4] = "Id be safe and warm";
r_text[5] = "If I was in L.A.";
r_text[6] = "California dreaming, On such a winter's day";
var i = Math.floor(7*Math.random())

document.write(r_text[i]);

//-->
</script>

0 个答案:

没有答案