User:Elominius/random character generator.js

/* random character generator */ /* Mobile users can test this script by copying it and pasting it after "javascript:" in the web browser's URL address bar. */

/* array which lists the characters */ var characters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var select_char = 0; /* Initializing variable to defeat JSHint warning; no functional difference. */

function random_char { /* randomly selects a position inside the array */ select_char = Math.floor(Math.random * characters.length);

/* Prevents an error in the unlikely event that Math.random results into exactly 1. It is unsure if it ever happens, but for being on the safe side. */ if (select_char == characters.length) select_char-=1;

/* returns character from selected position */ return characters[select_char]; }

/* alert character for demonstration purposes */ alert(random_char);