Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created September 23, 2017 01:47
Show Gist options
  • Save hyrious/8fcf8e2f8f2b07a7c8f8af50c6e434aa to your computer and use it in GitHub Desktop.
Save hyrious/8fcf8e2f8f2b07a7c8f8af50c6e434aa to your computer and use it in GitHub Desktop.
linear probability draw card
def draw b, c, d, q = rand
pc = 2.0 / ((d + 1) * (c - b + 1))
s = pb = d * pc
dp = (d - 1) * pc / (c - b)
while s < q
s += pb -= dp
b += 1
end
b
end
p Array.new(20) { draw 1, 200, 100 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment