Skip to content

Instantly share code, notes, and snippets.

View modullar's full-sized avatar
🏠
Working from home

Mouaz Heron modullar

🏠
Working from home
  • Berlin
View GitHub Profile
@O-I
O-I / weighted_random_sampling.md
Last active April 18, 2025 15:30
[TIx 8] Weighted Random Sampling in Ruby

One of the many reasons I love working with Ruby is it has a rich vocabulary that allows you to accomplish your goals with a minimal amount of code. If there isn't a method that does exactly what you want, it's usually possible to build an elegant solution yourself.

Let's take the example of simulating the rolling of a die.

We can represent a die as an array of its faces.

die = [*?⚀..?⚅]
# => ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]