Jump to content
  • Advertisement
Sign in to follow this  
FounderSim

Word Game: random % of when a letter should be displayed

This topic is 1337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The title may be a little confusing so I will try to the best of my ability to explain what I mean.

 

For games like scrabble/words with friends each match has a certain # of letters that can be used.

 

Now lets say for a game that has a endless amount of letters. I can't just choose them randomly 1-26 because the A and Z should be shown every 1 out of 26 times. This would cause most matches to end quicker then I would like because there are less "Real Words" with the letter A then with Z.

 

How would you create a random Letter being chosen or suggest to make it more fair?

 

 

I suppose I could make a little program to read every character from every word in a dictionary word list and find out the % of each character compared to the others, but I am sure there is an easier way?

Share this post


Link to post
Share on other sites
Advertisement

Wikipedia article on letter frequency. That has been known and studied for a very long time in different areas. There are plenty of tables with letter frequencies for different languages you can use. No need to make your own.

Share this post


Link to post
Share on other sites

"Now lets say for a game that has a endless amount of letters. I can't just choose them randomly 1-26 because the A and Z should be shown every 1 out of 26 times"

 

That's not how probability works. If you choose a random value between 1 and 26 several times you can get the same number 3 times in a row, one of the numbers on the 100th try only and another maybe 0 times since you have to stop at one time. That "1 out of 26" is true for one pick only, it's called an independant event, the fact that one number came out in a previous generation doesn't affect in any way the current one.

 

If you wanted to simulate that "1 our of 26 times" behaviour with an "endless amount of letters" you would actually need extra work, you'll need a list of already picked values and keep generating values until you get one that's not in the list.

Edited by DiegoSLTS

Share this post


Link to post
Share on other sites

As to the actual selection, what you describe sounds like weighted random selection. If I'm not much mistaken, it works something like this, in short:

  • Each item (items in this case being letters) is assigned a weight, with higher weights corresponding to higher probabilities of being selected.
  • Calculate the "total weight": the sum of the weights of the items.
  • Whenever you want to select from the items, do the following:
    • First generate a random value between 0 and the total weight
    • Create a "running total", initialised to 0
    • Finally, iterate over your items: Add the weight of the item to the running total; if this new running total value is higher than the random value, then select that item; otherwise, continue to the next item.
    • (This can be thought of as laying the items end-to-end in a line, with their length corresponding to their weight. The random value then corresponds to a point made at some distance down this line, and the iterative process checks the end-point of each item to see whether it is beyond the random value, and thus that the point lies within the line-segment of that item (the preceding item, if any, having already been checked).)

Share this post


Link to post
Share on other sites

That's not how probability works. If you choose a random value between 1 and 26 several times you can get the same number 3 times in a row, one of the numbers on the 100th try only and another maybe 0 times since you have to stop at one time. That "1 out of 26" is true for one pick only, it's called an independant event, the fact that one number came out in a previous generation doesn't affect in any way the current one.

 

If you wanted to simulate that "1 our of 26 times" behaviour with an "endless amount of letters" you would actually need extra work, you'll need a list of already picked values and keep generating values until you get one that's not in the list.

 

Thankfully it's a bit easier (and more efficient) than that; you can take an array of possible values, Fisher-Yates shuffle it, and iterate along the array, reshuffling when needed.

 

For the OP: So if you want more of any particular letter, you can just add more of that letter to your initial array.  So you could use an alphabet like "AAAABCDDEEEEEEFGHHH..." to start out with, so that E is chosen twice as often as H and six times more often than B.  (Or whatever distribution you want.)  

 

It might also be worth considering whether you want to prevent really bad draws (five Es in a row, seven consonants in a row, etc).  If so, then keep a list of recent letters like Diego says, and when the algorithm gives you a "bad" letter, just ignore it and ask for another.

Share this post


Link to post
Share on other sites

Thanks everyone. I wasn't expecting all these replies in such a short amount of time. I believe @Brother Bob hit it right on the money. The Letter frequency and the link works out even better since it has multiple languages.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!