For simplicity, use Notepad or another text editor to create the short JavaScript code. You can also use Web development software like Dreamweaver. The latter is easier to customize if you want to get a bit fancy with the display. Open a new file in Notepad and type the code below. The fourth line continues with the fifth line, which begins with the word “array. Do not insert a line break between lines four and five. Do not type the four asterisks; they are here only to keep this script from executing on the Web page where this article appears.
****<script>
function GetPassword()
{
var pwd=new array("plots","have","laid","induct","danger","first","convince","brother","crown","become","liv e","spite","still","course","king","late","halt","know","more","sure","clock");
var i=Math.floor(21*Math.random());
var n=Math.floor(21*Math.random());
window.alert(pwd[i] +"/" +pwd[n])
}
</script>
You can replace any of the words in the array with any other words. Arrays begin counting with zero, so the total number is always one more than you would expect. There are twenty-one words in the above example. If you increase or decrease the number then change the lines that define the index variables “i” and “n” to match the number of elements. For example, if using 25 words, the relevant code should read “var i=Math.floor(25*Math.random()); and “var n=Math.floor(25*Math.random());
The code defines a function called with some additional lines. The index variables are the result of two Javascript functions. Math.random creates a random number between .000 and .999. To ensure the total number of possible random numbers equals the total number of words, the result is multiplied by the number of words. A second function, Math.floor, truncates the result to an integer. The last line, “window.alert(pwd[i] +"/" +pwd[n])” opens a window and prints a new password consisting of two words separated by a slash mark (“/”). This can be any separation character you wish. You also can delete that item and the words will run together.