How do you simulate a dice? In javascript, It would be

function dice() {
  return Math.floor(Math.random() * 6) + 1
}

So how about biased dices, for example returns 1 in probability 1/4, returns 2 in probability 1/9, and so on?

If you get an interest in this, read this article.

Tags: algorithms