By Daniel · December 24, 2008
Generates a random word. The result may not be an actual dictionary term, but it should have a natural sound (resulting from a good consonant/vowel arrangement). This uses the random_letter script, so be sure to include that in your game.
// random_word()
consonants = floor(random(2)+2); // Customize to suit your needs
pass = "";
for (j = 1; j <= consonants; j += 1) {
if j == consonants then vowels = 0
else vowels = 1; // require at least one vowel if not end of word
vowels += floor(random(2));
c = random_letter(0); // Random consonant
pass += c; // Add consonant
if c == "q" then pass += "u"; // Force QU
repeat vowels pass += random_letter(1); // Add vowels
}
return pass;
Categories: String handling
There are no comments to display.
You must be signed in to post comments.