[swift-evolution] [Proposal] Random Unification

Thorsten Seitz tseitz42 at icloud.com
Wed Nov 29 00:10:08 CST 2017


Shouldn't it be

    random.choose(from: 1...6)

etc.?

-Thorsten 

> Am 28.11.2017 um 00:20 schrieb Martin Waitz via swift-evolution <swift-evolution at swift.org>:
> 
> Hello,
> 
>> 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.
> 
> -- 
> Martin
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171129/76a95cac/attachment.html>


More information about the swift-evolution mailing list