[swift-evolution] 'Random' Improvements

Pedro Ferreira plferreira4 at gmail.com
Mon Apr 3 14:24:31 CDT 2017


Thanks for the correction.
I guess that helps my point, its easy to get this sort of thing wrong, so
it would be a good candidate for being included in the standard library.

On Mon, Apr 3, 2017 at 6:53 PM, Peter Dillinger <
Peter.Dillinger at synopsys.com> wrote:

> > func getRandom(_ min: Int, _ max: Int) -> Int {
>
> >    let diff = max - min + 1
>
> >
>
> >    #if os(Linux)
>
> >        return min + Int(random() % diff)
>
> > ...
>
>
>
> Implementation detail: non-uniformity mistakes of the past should not be
> repeated.  http://stackoverflow.com/a/6852396/454544 (Timed out on
> finding a better reference.)
>
>
>
> --
>
> Peter Dillinger, Ph.D.
>
> Software Engineering Manager, Coverity Analysis, Software Integrity Group
> | Synopsys
>
> www.synopsys.com/software
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170403/e4483206/attachment.html>


More information about the swift-evolution mailing list