Python rng in a loop returns the same number all the time -


i'm running rng in loop , using random.choice(list) pick 2 words list , combine them. iterate 300 times, each time run same choice 300 times. if run script multiple times i'll different choice, within loop choice stays same. example:

run #1:     bob alice     bob alice     bob alice     bob alice run #2:     john charline     john charline     john charline     john charline etc... 

here's code:

import random  in range(1,301): #index starts @ 1 later reasons     pr = random.choice(pref) #string array containing prefixes     su = random.choice(suff) #string array containing suffixes     print (pr + su) 

i tried using random.randrange or random.randint same problem.

assuming pref in form:

pref = ['bob', 'suzy', 'dimitri"] 

and suff = ['smith', 'silvers', 'golds']

n = 5

for in range(n): pr = random.choice(pref) su = random.choice(suff) print (pr + ' ' + su)

should answer need. here output received when ran in terminal.

joe silvers alice smith joe smith alice smith bob silvers

so code fine, guess. maybe if post entire output, there variations down list.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -