Randomly generate letters - sorta

Trying my hand at a word game in HTML5 / JavaScript.

Is there JavaScript out there that can create randomly generated letters, such that you could have a fair chance of forming words.

The letters will move across the screen from right to left.  The user will pick letters to form words.

But I need a fair mix of random consonants and vowels.  The question is - what is a fair mix and how to generate it?

Suggestions?


Here is what I have so far:

letArray = ['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'];

        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());
        $('#word').val($('#word').val() + genRandomLetter());


        function genRandomLetter() {
           return letArray[Math.floor((Math.random() * 25) + 0)];
        }

Open in new window



Output:

wsrbcizhqopngjwswyympqfnyedvjl

possible words:

win
won
wig
whim
sin
son
bin
bid

etc....
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
this would be a bit of trial and error. certainly put a weighting on more common consonants and of course the vowels. then tweak these for a "difficulty" level in your game.
Tom KnowltonWeb developerAuthor Commented:
Yeah....

Makes sense!
RobOwner (Aidellio)Commented:
I did a similar thing when I made a sudoku game. just had to tweak the randomness until you could solve it!
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Tom KnowltonWeb developerAuthor Commented:
Cool!
RobOwner (Aidellio)Commented:
So create another array with 24 elements, each signifying a weight for the corresponding letter of the alphabet.  Then use that when creating your random letters.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom BeckCommented:
I would use something like this as a guide for the frequency of each letter of the alphabet.

http://www.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html
Tom KnowltonWeb developerAuthor Commented:
Thanks guys!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.