> On Nov 30, 2017, at 5:02 PM, Jonathan Hull <jh...@gbis.com> wrote:
>
>
>> On Nov 30, 2017, at 3:52 PM, Dave DeLong <sw...@davedelong.com
>> <mailto:sw...@davedelong.com>> wrote:
>>
>> What is the useful distinction between generating a random value, and
>> choosing a random element from a collection of all possible values?
>
> I don’t have to generate (or keep in memory) that collection.
>
> I gave an example before of an easy to add API for random colors which allow
> their saturation, lightness, and alpha to be fixed. I use something very
> similar all the time in some graphics code I have (varying only the hue or
> saturation). I also do the same with Sizes and CGVectors. How would you
> represent that as a collection to choose an element from?
You’re not picking a random color. You’re picking a random hue or a random
saturation, and then constructing a color based off that. In other words,
you’re choosing a value from 0…1:
let color = UIColor(hue: (0…1.0).random(), saturation: knownSaturationValue,
brightness: knownBrightnessValue, alpha: knownAlphaValue)
Dave
> Also, for most of my use cases, I *need* to be able to plug in a repeatably
> random source… otherwise pixels will start jumping around the screen when
> people resize things.
That’s cool; I’m totally in favor of the RandomSource API as a way to model
different distributions or algorithms or whatever. I just don’t thing
“Foo.random” is a good idea.
Cheers
Dave
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution