Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Programming random word generator

edited April 2016 in OpenSesame

I've been shuffling a list of words randomly, but I'm trying to create a program that picks 50 of these random words. How can I stop it at 50 items? Thanks in advance for any help!

item_list = ['AirFreshener', 'Apples', 'ArtificialCherry', 'artificialfruit', 'artificialfruitpunch', 'artificialgrape', 'bodywashsoap', 'carfreshener', 'chapstick', 'chemicals', 'cherrymedicine', 'cleanfresh', 'cottoncandy', 'deodorant', 'figs', 'fireplace', 'flowers', 'fruit', 'fruitcleaningsolution', 'fruitygum', 'fruityperfume', 'fruityshampoo', 'girlysoap', 'grapefruit', 'grapes', 'gum', 'handsoap', 'jello', 'johnson', 'juice', 'laundrydetergent', 'lavender', 'peaches', 'pears', 'pineapples', 'rootbeer', 'sangria', 'soap', 'sourgreenapple', 'springtime', 'stalewater', 'strawberrychapstick', 'strawberryfruitcandy', 'sugar', 'sugarycandy', 'sweet', 'tangy', 'watermeloncandy', 'applecider', 'appleflavoredcandy', 'artificialbanana', 'artificialwatermelon', 'bananacandy', 'bananamilkshake', 'bananas', 'blueberries', 'bubblegum', 'caramelapple','cocoa', 'candy', 'jollyranchers', 'mango', 'orangewithcloves', 'papaya', 'pinacolada', 'pudding', 'raisins', 'restaurantkitchen', 'smoothie', 'starburstcandy', 'strawberrybananasmoothie', 'sweetchemical', 'sweetfruit' ,'tropicalfruit', 'yogurt', 'allspice', 'artificialcinnamon', 'atomicfireballcandy', 'candlewax', 'cinnamonflavor', 'cinnamonroll', 'freshmint', 'mint', 'mintmouthwash', 'vaseline', 'almond', 'applescinnamon', 'asiandrinks', 'badincense', 'boba', 'burntchai', 'cedarwood', 'chai', 'christmassweetsandcandy', 'cloves', 'cuminspice', 'darkchocolate', 'exoticforeign', 'firewood','fishflakes','gingerbreadcookies','herbaltea','indianfoodspices','insideofamansleathershoe','leathercleanerpolish','lychee','metalcarpart','milktea','nutmeg','nuts','oldfood','pumpkin','pumpkinpiespices','rosebuds','rottenfruit','rottenmeat','rottingfood','rottingmintleaves','salmon','smoky','tastydrinks','tobacco','turkishdelight','woodshavings','acafe','almondbutter','almondchocolate','bakedgoods','baking','brownsugar','butter','butteredpopcorn','butterscotch','campfire','cappuccino','caramel','caramelcoffee','caramelcorn','chocolate','coffee','coffeebeans','coffeegrounds','coffeeshop','cookies','cornnuts','creamer','doctorsoffice','freshlybakedcake','fudge','grocerystore','hotchocolate','icecream','javachipicecream','kettlecorn','lumber','marshmallowflavoredjellybean','mocha','molasses','popcorn','smooth','starbucks','stinkycheese','tart','vanilla','vanillahazelnutcoffeewithcream','warm','whitechocolate','badoranges','beets','carfumesexhaust','catbreath','catfood','cows','creamedcorn','decompostingforestplants','diaper','dirtytoiletwater','driedoldstalesweat','fishmarket','freshfish','fungus','gasstoveoven','harbor','insideofarectum','lobster','mushrooms','oldseaweed','poopfeces','portapotty','rawfish','rottenfish','rotten','rottingtrash','salmoneggs_1','sardines','seaweed','shrimp','shrimpflavoredchips','smellyfeet','squid','staleunwashedbodies','tartarsauce','vomit','womensbathroom','ashes','asianfood','bitter','bitterherbs','canolaoil','chili','crab','deadfish','dirtyclotheslinenlaundry','ethnicfood','fish','fishingdocks','flavorful','garlic','garlicbread','garliccloves','garlicfries','horseradish','kimchi','lemonpepper','meat','onions','overlypepperedsteak','pastasauce','pepper','picklejuice','rawmeat','rottentopramenflavoring','salty','sauce','seafood','seasoningsalt','severelyburntfood','shellfish','soysauce','spicy','sulfur','sweat','thaifood','vinegar','bodyodor','burntrubber','chalk','classroom','cleanclotheslinenlaundry','colognethatdadswear','couches','departmentstore','dustyclothes','fabricsoftenerdryersheets','freshshowersmell','hospitals','linen','chapstick','livingmossflowers','lobby','mensdeodorant','middleagedwomansperfume','mildew','mothballs','musk','newcarpet','newfurniture','old','oldcloset','oldfolkshome','oldladyperfume','oldman','oldmustyroom','scentedoil','shoecleanerpolish','shoes','smoke','somethingnew','spaproducts','tar','wetwood','woods','appleflavored','badnoodles','cilantro','citrusoil','freshplants','fruitloops','glue','lemonscentedcleaningproducts','lemonlime','limes','orangecleaningsupplies','salad','sour','sriracha','coldmedicine','fennel','gumdrops','gummycandy','markers','mousse','oldclothes','permanentmarkers','pinescentedcarfreshener','twizzlers','wood','bathroom','clementineorange','freshcutlemonlime','freshorange','greenapple','gummy','gummybearsworms','healthy','lemonpie','lemonlimesoda','lemonade','lemonadepowdermix','lollipop','mandarinoranges','orangejello','orangejuice','orangepeels','starburst','tangerine','aloevera','altoid','breathmint','candycanes','chocolatemint','cinnamon','cinnamongum','citrus','gingerbreadhouse','hardcandy','holidays','juniormints','mintchapstick','mintchocolatechip','mintgum','mouthwash','oranges','peppermint','peppermintcandy','peppermintgum','restaurantcandiesmints','spearmintgum','toothpaste','yorkpeppermintpatty','aerosol','fruitpunch','artificialstrawberry','berries','chalky','cherries','christmas','coconut','driedfruit','fermentingfruit','fruitcandy','fruitjuice','fruitsalad','grapejuice','gummy','japanesedrinkorcandy','juicy','laundry','lemoncandy','lemons','melon','mornings','passionfruit','applejuice','pine','raspberries','raspberrybodyspray','raspberrylipgloss','soda','sourcandy','strawberries','strawberrybanana','summer','sweetandsour','sweetener','tropicalairfreshener','tropicalscentoldspice','vitamins','aftershave','babypowder','bacon','bathsalts','bathroomscentsticks','beautysupplyshop','candles','carpet','church','citruscleaner','citrusshampoo','cleanfreshair','cold','cologne','febreeze','floralairfreshener','floralperfume','floralsoap','forest','garbagetrash','ginger','grossperfume','herbs','hippyperfume','honey','hotelsoap','incense','ink','insectrepellent','lavenderlotionsoap','lemonperfume','licorice','makeup','manly','manure','menscologne','mintcandies','moisturizerlotion','motor','musty','oldcarpet','oldperfume','oldpersonperfume','oldspiceproducts','perfume','plants','pleasantrubber','roseoilperfume','roses','scratchandsniffsticker','shampoo','spearmint','womensperfume','artificial','artificialscentedmarkers','asphalt','bathroomcleaner','blacklicorice', 'bleach','car','celery','chinatown','cleaningproducts','coughdrops','coughsyrup','dirt','dryerasemarkers','earth','eucalyptus','eucalyptusairfreshener','gardens','gasolinefuel','greenhouses','handsanitizer','indoors','leather','medicine','menthol','mints','musclecream','nailpolish','natural','nature','oldpeople','oldpeopleshouses','outdoorsoutside','paint','pinecleaningsolution','pineneedlescones','plantroots','potpourri','refreshing','rubber','rubbingalcohol','rust','sap','sawdust','snow','soil','spices','stainremover','sterile','teatreeoil','treebark','treesap','trees','vaporrub','wetpaint','winter','woodpolishcleaner']

shuffle(item_list)

for item in item_list:
exp.items[item].prepare()

for item in item_list:
exp.items[item].run()

Comments

  • edited 1:33PM

    Hi,

    There are multiple options how do it. Here are 2:


    # 1) use random.sample to select samples from the list without replacement import random item_list = ['long','list','with','many','items'] no_of_samples = 2 # in your case 50 random.shuffle(item_list) samples = random.sample(item_list, no_of_samples) # 2) Shuffle your item list and pop the first elements every time when needed item_list = ['long','list','with','many','items'] random.shuffle(item_list) # later in your trial_loop, you can access only one item from this list # e.g. to draw it on a canvas: word = item_list.pop() cv = canvas() cv.text(word) cv.show() clock.sleep(3000)

    Does this make sense?

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.