Skip to content

Instantly share code, notes, and snippets.

View gyfis's full-sized avatar
:shipit:
pushing code to production

Tomáš Hromada gyfis

:shipit:
pushing code to production
View GitHub Profile
@gyfis
gyfis / weighted_random_sampling.md
Created November 1, 2019 09:36 — forked from O-I/weighted_random_sampling.md
[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 = [*?⚀..?⚅]
# => ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]