js产生两组随机数,第一组产生不重复随机数组,第二组产生不包括第一组数据的不重复随机数

js产生两组随机数,第一组产生不重复随机数组,第二组产生不包括第一组数据的不重复随机数

这是我在做下面的抽奖小系统才有这样的问题:  
在test1.jsp在1-500中产生不重复随机数,比如第一组随机产生不重复随机两个数12,23,在第二个页面test2.jsp产

生的两个数中不包括12,23,该怎么实现(所有产生的数不重复)
//test1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path

+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'tpl.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="jQuery.js"></script>
	<link rel="stylesheet" type="text/css" href="style.css">
   <script type="text/javascript">
        var c=0
	var t
function start()
	{
	var txt1=Math.round(Math.random() * (500- 1) + 1);
	var txt2=Math.round(Math.random() * (500- 1) + 1);
        document. getElementById('txt1').value=txt1;
	document. getElementById('txt2').value=txt2;
        t=setTimeout("start()",60)
}
function over()
	{
	clearTimeout(t);
}
</script>
  </head>
<body>
   <input type="text" id="txt1" style="width:60px;height:50px;font-size:30px;">
   <input type="text" id="txt2" style="width:60px;height:50px;font-size:30px;">
   <div class="start" ><img src="images/start1.png" onclick="start()"/></div>
   <div class="over"><img src="images/over.png" onclick="over()" /></div>
</body>
</html>


//test2.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path

+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'tpl.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="jQuery.js"></script>
	<link rel="stylesheet" type="text/css" href="style.css">
   <script type="text/javascript">
function start()
	{
	var txt3=Math.round(Math.random() * (500- 1) + 1);
	var txt4=Math.round(Math.random() * (500- 1) + 1);
        document. getElementById('txt3').value=txt3;
	document. getElementById('txt4').value=txt4;
        t=setTimeout("start()",60)
}
function over()
	{
	clearTimeout(t);
}
</script>
  </head>
<body>
   <li><input type="text" id="txt3" style="width:60px;height:50px;font-size:30px;"></li>
   <li><input type="text" id="txt4" style="width:60px;height:50px;font-size:30px;"></li>
   <div class="start" ><img src="images/start1.png" onclick="start()"/></div>
   <div class="over"><img src="images/over.png" onclick="over()" /></div>
</body>
</html>

你可能感兴趣的:(JavaScript)