Prindol

DESIGN, HTML5, CSS3, DOM, Jquery, JSON, Actionscript2/3, Linux, IIS

You are not logged in.

#1 2016-11-28 17:25:41

skydown
Administrator
Registered: 2011-07-25
Posts: 315

[JAVASCRIPT] 랜덤문자, 난수발생

랜덤문자, 난수발생 스크립트

randomText.html

random(글자길이, 생성갯수);

<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>title</title>
</head>
<body>
<h1>random text</h1>
<div id="random"></div>
<div>
  <p><input type="text" onkeydown="enter(event, value);" /></p>
</div>
<script>
random(5,9);
function random(min,max) {
var arr = [];
var nansu="";
  for(var j=1;j<=max;j++){
    for(var i=1;i<=min;i++){
     if( Math.floor(Math.random() * 100)+10 > 50){
      //대문자 A-Z 랜덤 알파벳 생성
      nansu += String.fromCharCode((Math.random() * 26) +65);
     }else{
      // 소문자 a-z 랜덤 알파벳 생성
      nansu += String.fromCharCode((Math.random() * 26) +97);
     }
    }
    arr += j +" "+ nansu +"<br>\n";
    nansu = "";
  }
  document.getElementById("random").innerHTML = arr;
}
function enter(event, value) {
  if (event.which == 13 || event.keyCode == 13) {//ENTER
    //code to execute here
    var min = value.split(',')[0]
    var max = value.split(',')[1]
    random(min, max);
    return false;
  }
  return true;
};
</script>
</body>
</html>

Offline

Board footer

Powered by FluxBB