SHARE
TWEET

Untitled

a guest Jul 17th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.     <title>Random Word Generator</title>
  6.     <script language="javascript" type="text/javascript">
  7.  
  8.         var validCharacters = new Array();
  9.         validCharacters[0] = "a";
  10.         validCharacters[1] = "b";
  11.         validCharacters[2] = "c";
  12.         validCharacters[3] = "d";
  13.         validCharacters[4] = "e";
  14.         validCharacters[5] = "f";
  15.         validCharacters[6] = "g";
  16.         validCharacters[7] = "h";
  17.         validCharacters[8] = "i";
  18.         validCharacters[9] = "j";
  19.         validCharacters[10] = "k";
  20.         validCharacters[11] = "l";
  21.         validCharacters[12] = "m";
  22.         validCharacters[13] = "n";
  23.         validCharacters[14] = "o";
  24.         validCharacters[15] = "p";
  25.         validCharacters[16] = "q";
  26.         validCharacters[17] = "r";
  27.         validCharacters[18] = "s";
  28.         validCharacters[19] = "t";
  29.         validCharacters[20] = "u";
  30.         validCharacters[21] = "v";
  31.         validCharacters[22] = "w";
  32.         validCharacters[23] = "x";
  33.         validCharacters[24] = "y";
  34.         validCharacters[25] = "z";
  35.    
  36.         function randomiser() {
  37.             var outputDiv = document.getElementById("output");
  38.  
  39.             var numberOfWords = document.forms[0].numberOfWords.value;
  40.             var wordPattern = document.forms[0].wordPattern.value;
  41.  
  42.             outputDiv.innerHTML = "";
  43.  
  44.             var randomWordsHTML = "";
  45.        
  46.        
  47.             for (var i = 1; i <= numberOfWords; i++) {
  48.                 var randomWord = generateRandomWord(wordPattern);
  49.                
  50.                 randomWordsHTML += randomWord + "<br />";
  51.             }
  52.  
  53.             outputDiv.innerHTML = randomWordsHTML;
  54.         }
  55.  
  56.         function generateRandomWord(wordPattern) {
  57.             var randomWord = "";
  58.             var wordLength = wordPattern.length;
  59.  
  60.             for (var i = 0; i < wordLength; i++) {
  61.                 if (wordPattern.charAt(i) == "l") {    
  62.                     randomWord += validCharacters[getRandomNumber(25)];
  63.                 } else if (wordPattern.charAt(i) == "n") {
  64.                     randomWord += getRandomNumber(9);
  65.                 }
  66.             }
  67.            
  68.             return randomWord;
  69.         }
  70.        
  71.  
  72.         function getRandomNumber(max) {
  73.             return Math.floor(Math.random() * (max + 1));
  74.         }
  75.     </script>
  76. </head>
  77. <body>
  78. <form action="#">
  79. Number of words: <input type="text" name="numberOfWords" />
  80. <br />
  81. Word pattern: <input type="text" name="wordPattern" /> (eg. lllnn, will generate words of length 5 made of 3 letters ('l') and 2 numbers ('n'))
  82. <br />
  83. <input type="button" name="randomise" value="Generate Random Words" onclick="randomiser();" />
  84. </form>
  85. <br />
  86. <h2>Output</h2>
  87. <hr />
  88. <div id="output">
  89. </div>
  90. </body>
  91. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top