Skip to content

Instantly share code, notes, and snippets.

@aesnyder
aesnyder / random-weighted.coffee
Last active October 22, 2017 16:55
Weighted random value in underscore or lodash
## First you can generate a weighted array
weighted 1: true, 2: false # [true, false, false]
weighted 1: true, 3: false # [true, false, false, false]
## Then random picks one randomly
## The following will return true or false with a 1:3 ratio
random weighted 1: true, 3: false