[swift-evolution] [Proposal] Random Unification
erica at ericasadun.com
Wed Nov 29 20:16:40 CST 2017
On Nov 28, 2017, at 11:10 PM, Thorsten Seitz via swift-evolution <swift-evolution at swift.org> wrote:
> Shouldn't it be
> random.choose(from: 1...6)
Doesn't `choose` usually take two arguments, the `count` to choose (presumably defaulting to 1) and the collection to choose `from`?
> Am 28.11.2017 um 00:20 schrieb Martin Waitz via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
>>> 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.
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution