Skip to content

Instantly share code, notes, and snippets.

View morteza's full-sized avatar
🍱

Morteza Ansarinia morteza

🍱
  • Luxembourg
View GitHub Profile
@morteza
morteza / weighted_random.scala
Created May 31, 2018 14:10 — forked from TJC/weighted_random.scala
Solution to scala-melb challenge, Mar 14 2012
// This is a fairly ugly solution; in a hurry and didn't spend much time on it.
import scala.util.Random
case class WeightedItem[T](item: T, weight: Double)
val items = Seq(WeightedItem("Red", 1d/6), WeightedItem("Blue", 2d/6),
WeightedItem("Green", 3d/6) )
def weightedSelection[T](