Skip to content

Try improved method for generating bounded random integers #75395

Description

@danmoseley

swiftlang/swift#39143 (Apache license)

Currently we use a simple rejection loop for generating int/long in a range

and other overloads. It may be that the Swift algorithm above is faster.

(Note that our existing algorithm is dropping high bits of the raw random result to minimize the rejections. If we can avoid doing that possibly it would improve the distribution?).

(I'm ignoring our legacy seeded impl which prefers reproducibility)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions