I'm probably missing something important, here, so bear with me. The suggestion works for this specific use case, but what role does the number 10 play? If it's tied to my use case's particular array size, then this solution won't scale for use with other arrays. For example, if I make the array size 20, I'll never get even values from this algorithm. This leads me to believe that what I need to do is override the template method that accepts the max value, perhaps like this:
func next<T>(upperBound: T) -> T where T : FixedWidthInteger, T : UnsignedInteger {
defer { current += 1 }
return T(current) &* (T.max/upperBound)
}
However, that does not appear to get called when randomElement() or random(in:) is called.
Topic:
Programming Languages
SubTopic:
Swift
Tags: