Random sentence from book: Difference between revisions

m
Line 15:
=={{header|Julia}}==
<lang julia>""" weighted random pick of items in a Dict{String, Int} where keys are words, values counts """
function weightedrandompick(sdictdict, total)
n = rand(1:total)
for key in keys(sdictdict)
n -= sdictdict[key]
if n <= 0
return key
Line 76:
end
end
followsums = SortedDictDict(key => sum(values(follows[key])) for key in keys(follows))
follow2sums = SortedDictDict(key => sum(values(follows2[key])) for key in keys(follows2))
afterstopsum = sum(values(afterstop))
 
4,104

edits