Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<input type="text" id="text" value="ok"/>
<input type="button" value="生成随机数" onclick="my_ran(3,2,20)" id="cre" />
<input type="button" value="清空" onclick="del()" />
</body>
</html>
 
function my_ran(n,min,max){
  var arr=[];
  for(i=0;i<n;i++){
    arr[i]=parseInt(Math.random()*(max-min+1)+min);
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(arr[i]==arr[j]){
        my_ran(n,min,max);
        return fault;
      }
    }
  }
  document.getElementById("text").value=arr;
}
function del(){
  document.getElementById("text").value="";
}
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers