1. 무작위로 4 자리 랜덤 숫자를 생성합니다
<script language = "javaScript">/*** 무작위로 4 비트 랜덤 숫자*http : //www.yulu.vevb.com*/document.write (parseint (10*math.random ())); // random random integer document.write (math.floor (math.random ()*10+1)); // 랜덤 정수 함수 rndnum (n) {var rnd = ""; for (var i = 0; i <n; i ++) rnd+= math.floor (math.random ()*10); return rnd;} document.write (rndnum (4)); // 지정된 숫자 수의 임의 수에 대한 임의의 정수를 출력 </script>2. 지정된 데이터 범위의 임의 수치를 무작위로 생성합니다
1) 1에서 모든 값으로 시작하십시오
parseint (math.random ()*상한+1);
2) 모든 값에서 모든 값으로 시작하십시오
<cript> parseint (math.random ()*(상한선 제한+1)+하한); 함수 frandomby (아래) {switch (arguments.length) {case 1 : parseint (math.random ()*아래+1); 사례 2 : parseint (math.random ()*(오버-언더 + 1) + 아래); 기본값 : 반환 0; }} document.write (Frandomby (1,100)); // 지정된 범위에서 임의 숫자의 임의 정수를 출력 </script> // 설정된 텍스트 상자의 규칙에 따라 다른 값을 부탁드립니다 [확장 <Script> wind o [0] .Value = Frandomby (1,10); o [1] .Value = Frandomby (11,20); o [2] .Value = Frandomby (1,100); o [3] .Value = Frandomby (51,100); } < /script> 1-10 : <input type = "text" /> <br /> 11-20 : <입력 유형 = "text" /> <br /> 1-100 : <input type = "text" /<br /> 51-100 : <입력 유형 = "text" /> <br />3. 확장 예 :
<html> <head> <title> 랜덤 숫자 생성 수학-www.vevb.com </title> </head> <body> <script language = "javaScript"type = "text/javaScript"> total = 0for (i = 1; i <= 5000; num = math.random (); 총+= num} 평균 = 총/5000; 평균 = math.round (평균*1000) /1000 ;document.write ( "<h1> 평균 :"+평균+"</h1>") </script> </body> </html>
JS에서 임의의 숫자 (지정된 범위)를 생성하기위한 위의 예제 코드는 내가 공유하는 모든 내용입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.