[{"data":1,"prerenderedAt":410},["ShallowReactive",2],{"/rnd/weighted-one-of-list":3,"/rnd/weighted-one-of-list-surround":399},{"id":4,"title":5,"body":6,"description":366,"extension":367,"meta":368,"navigation":385,"path":395,"seo":396,"stem":397,"__hash__":398},"content/rnd/weighted-one-of-list.md","Rnd Extension Dictionary: weighted-one-of-list",{"type":7,"value":8,"toc":355},"minimark",[9],[10,11,15,16,15,26,51,55,60,61,64,68,69,75,76,79,82,183,193,211,275],"div",{"className":12,"id":14},[13],"dict_entry","weighted-one-of-list","\n  ",[17,18,20,21,15],"h3",{"id":19},"rndweighted-one-of-list","\n    ",[22,23,25],"a",{"href":24},"#weighted-one-of-list","rnd:weighted-one-of-list",[27,28,32],"h4",{"id":29,"className":30},"rndweighted-one-of-list-netlogo-list-anonymous-reporter",[31],"section-heading",[22,33,20,37,15],{"className":34,"href":36},[35],"section-anchor","#----rndweighted-one-of-list-netlogo-list-anonymous-reporter--",[38,39,42,43,47,48],"span",{"className":40},[41],"prim_example","rnd:weighted-one-of-list ",[44,45,46],"i",{},"netlogo-list"," ",[44,49,50],{},"anonymous-reporter",[52,53,54],"p",{},"Reports a random item from ",[10,56,57],{},[44,58,59],{},"list",".",[52,62,63],{},"The probability of each item being picked is proportional to the weight given by the ",[10,65,66],{},[44,67,50],{}," for that item. The weights must not be negative. The first argument passed to the anonymous procedure refers to the list item. (See the ",[22,70,74],{"href":71,"rel":72},"https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures",[73],"nofollow","Anonymous Procedures section"," of the Programming Guide for more details.)",[52,77,78],{},"It is an error for the list to be empty.",[52,80,81],{},"A common way to use the primitive is to have a list of lists, where the first item of each sublist is the thing you want to choose and the second item is the weight. Here is a short example:",[83,84,85],"pre",{},[86,87,88,47,94,99,100,47,105,110,111,47,115,119,120,123,47,127,131,132,134,135,140,134,142,146,134,148,47,152,47,157,47,160,163,164,167,168,47,172,47,176,179,180,182],"code",{},[38,89,93],{"className":90},[91,92],"token","command","let",[38,95,98],{"className":96},[91,97],"variable","pairs"," [ [ ",[38,101,104],{"className":102},[91,103],"string","\"A\"",[38,106,109],{"className":107},[91,108],"number","0.2"," ] [ ",[38,112,114],{"className":113},[91,103],"\"B\"",[38,116,118],{"className":117},[91,108],"0.8"," ] ]",[121,122],"br",{},[38,124,126],{"className":125},[91,92],"repeat",[38,128,130],{"className":129},[91,108],"25"," [",[121,133],{},"  ",[38,136,139],{"className":137},[91,138],"comment","; report the first item of the pair selected using",[121,141],{},[38,143,145],{"className":144},[91,138],"; the second item (i.e., `last p`) as the weight",[121,147],{},[38,149,151],{"className":150},[91,92],"type",[38,153,156],{"className":154},[91,155],"reporter","first",[38,158,25],{"className":159},[91,97],[38,161,98],{"className":162},[91,97]," [ [",[38,165,52],{"className":166},[91,97],"] ",[38,169,171],{"className":170},[91,155],"->",[38,173,175],{"className":174},[91,155],"last",[38,177,52],{"className":178},[91,97]," ]",[121,181],{},"]",[52,184,185,186,189,190,60],{},"This should print ",[86,187,188],{},"B"," roughly four times more often than it prints ",[86,191,192],{},"A",[52,194,195,196,203,204,210],{},"If you happen to have your items and your weights in two separate lists, you can combine them into pairs by using a combination of ",[22,197,200],{"href":198,"rel":199},"http://ccl.northwestern.edu/netlogo/docs/dictionary.html#map",[73],[86,201,202],{},"map"," and ",[22,205,208],{"href":206,"rel":207},"http://ccl.northwestern.edu/netlogo/docs/dictionary.html#list",[73],[86,209,59],{},":",[83,212,213],{},[86,214,215,47,218,222,223,47,226,47,229,179,233,235,47,238,222,242,47,246,47,249,179,253,255,47,258,261,262,47,265,47,268,47,271,274],{},[38,216,93],{"className":217},[91,92],[38,219,221],{"className":220},[91,97],"items"," [ ",[38,224,104],{"className":225},[91,103],[38,227,114],{"className":228},[91,103],[38,230,232],{"className":231},[91,103],"\"C\"",[121,234],{},[38,236,93],{"className":237},[91,92],[38,239,241],{"className":240},[91,97],"weights",[38,243,245],{"className":244},[91,108],"0.1",[38,247,109],{"className":248},[91,108],[38,250,252],{"className":251},[91,108],"0.7",[121,254],{},[38,256,93],{"className":257},[91,92],[38,259,98],{"className":260},[91,97]," (",[38,263,202],{"className":264},[91,155],[38,266,59],{"className":267},[91,155],[38,269,221],{"className":270},[91,97],[38,272,241],{"className":273},[91,97],")",[52,276,277,278,283,284,286,287,289,290,305,306,311,312,317,318,323,324,60],{},"Since we apply ",[22,279,281],{"href":198,"rel":280},[73],[86,282,202],{}," to both the ",[86,285,221],{}," list and the ",[86,288,241],{}," list, the parentheses are needed in ",[86,291,292,293,47,296,47,299,47,302,274],{},"(",[38,294,202],{"className":295},[91,155],[38,297,59],{"className":298},[91,155],[38,300,221],{"className":301},[91,97],[38,303,241],{"className":304},[91,97],". We also use the concise anonymous procedure syntax (see the ",[22,307,310],{"href":308,"rel":309},"http://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures",[73],"programming guide",") to pass ",[22,313,315],{"href":206,"rel":314},[73],[86,316,59],{}," as the reporter for ",[22,319,321],{"href":198,"rel":320},[73],[86,322,202],{},". The same thing could have been written ",[86,325,292,326,163,329,47,332,167,336,47,339,47,342,47,345,348,349,47,352,274],{},[38,327,202],{"className":328},[91,155],[38,330,22],{"className":331},[91,97],[38,333,335],{"className":334},[91,97],"b",[38,337,171],{"className":338},[91,155],[38,340,59],{"className":341},[91,155],[38,343,22],{"className":344},[91,97],[38,346,335],{"className":347},[91,97]," ] ",[38,350,221],{"className":351},[91,97],[38,353,241],{"className":354},[91,97],{"title":356,"searchDepth":357,"depth":358,"links":359},"",5,3,[360],{"id":19,"depth":358,"text":361,"children":362},"\n    rnd:weighted-one-of-list\n  ",[363],{"id":29,"depth":364,"text":365},4,"\n    rnd:weighted-one-of-list netlogo-list anonymous-reporter\n  ","Documentation for the weighted-one-of-list primitive.","md",{"source":369,"metadataOutputPath":370,"projectConfig":371,"language":378,"inheritFrom":386,"output":385,"version":372,"layout":387,"dictionaryDisplayName":388,"dictionaryHomeDirectory":389,"indexFileURI":390,"currentItemId":14,"currentItemLabel":25,"primRoot":391,"icon":392,"extensionName":393,"assetsRoot":373},"../../external/extensions/rnd/rnd/weighted-one-of-list.md","content/rnd/weighted-one-of-list.metadata.yaml",{"version":372,"projectRoot":60,"scanRoot":373,"outputRoot":374,"defaults":375,"engine":381,"partials":382,"dedupeIdenticalDiskWrites":385},"7.0.4","/home/runner/work/Helio/Helio/external/extensions/rnd","content",{"inheritFrom":376,"language":378,"output":379,"extension":367,"title":380,"version":372},[377],0,"en",false,"NetLogo User Manual","mustache",{"directoryPaths":383,"extensions":384},[60],[381,367],true,[377],"catalog","Rnd Extension Dictionary","/rnd.html","/_index/extensions/rnd.txt","rnd","i-mingcute-random-line",{"shortName":391,"fullName":394},"Rnd","/rnd/weighted-one-of-list",{"title":5,"description":366},"rnd/weighted-one-of-list","BVMXJFbIdT7FLV7di0hTKOZPpfDSlUqmTnuFuzHtZJc",[400,405],{"title":401,"path":402,"stem":403,"description":404},"Rnd Extension Dictionary: weighted-one-of","/rnd/weighted-one-of","rnd/weighted-one-of","Documentation for the weighted-one-of primitive.",{"title":406,"path":407,"stem":408,"description":409},"Sample Model","/sample","sample","Walkthrough of a sample NetLogo model to demonstrate key concepts and features of the modeling environment.",1777657898197]