How to make python choose randomly between multiple strings?
            Asked
            
        
        
            Active
            
        
            Viewed 1.6k times
        
    6
            
            
        - 
                    possible duplicate of [How do I randomly select an item from a list using Python?](http://stackoverflow.com/questions/306400/how-do-i-randomly-select-an-item-from-a-list-using-python) – Dan Hlavenka Jul 07 '14 at 23:57
- 
                    2Paste your code into your question, don't take a screenshot and post that on an external site... – Wooble Jul 08 '14 at 00:04
- 
                    Heya, welcome to Stack Overflow! Generally it's Good Form to include your code here. It's ok to include a link to a fiddle like you have here - but we also want to see your code... don't forget that programmers are leery of clicking on links to external sites in case they are spam or phishing attempts... ;) Also - that fiddle will go away sometime, and we want Stack overflow to be eternal... and the only way that will happen is if you put your code here. – Taryn East Jul 08 '14 at 00:05
- 
                    Real code so we an copy/paste - not a screenshot :) – Taryn East Jul 08 '14 at 00:06
- 
                    And *especially* not a screenshot too small to read :) – Tom Zych Jul 08 '14 at 00:34
2 Answers
20
            Add them all to a list, import random, then call the choice method like so:
In [1]: import random
In [2]: hello = ['hi', 'hello', 'yo', 'bonjour', 'hola', 'salaam']
In [3]: random.choice(hello)
Out[3]: 'bonjour'
- 
                    No problem, apparently other users hated my comment though. Have fun with python! It's a great language. – Robeezy Jul 08 '14 at 00:26
 
     
     
     
     
    