Mar-19-2019, 11:43 PM
(Mar-19-2019, 11:37 PM)ichabod801 Wrote:(Mar-19-2019, 11:31 PM)Truman Wrote: Does that mean that some words will never be returned? Or they will because dictionaries are unordered? In that case, why do we need to do this calculation if we can randomly choose any word?
The only time a word would never be returned is if it's weight was 0. Then it would have a probability 0 / t of being returned. It means that some words are more likely to be returned than others, and some words are less like to be returned than others. The standard random.choice() selects every item in the provided sequence with equal likelihood.
That's exactly why I don't understand why the author of this code used weighted random selection. Wouldn't it be more 'fair' that each word has an equal chance of being selected?