[swift-evolution] [Proposal] Random Unification

Martin Waitz tali at admingilde.org
Mon Nov 27 17:20:22 CST 2017


> Maybe we call the default RNG instance `random`, and then give the `random(in:)` methods another name, like `choose(in:)`?
> 	let diceRoll = random.choose(in: 1...6)
> 	let card = random.choose(in: deck)
> 	let isHeads = random.choose(in: [true, false])
> 	let probability = random.choose(in: 0.0...1.0)
> 	let diceRoll = rng.choose(in: 1...6)
> 	let card = rng.choose(in: deck)
> 	let isHeads = rng.choose(in: [true, false])
> 	let probability = rng.choose(in: 0.0...1.0)

I like this design a lot. After all, `random` is not a property of some type or instance, but we want to generate a new random element within some range/based on some given set.
Modeling that as methods of the RNG seems to be much more natural.


More information about the swift-evolution mailing list