Skip to content

Look into this alleged optimal algorithm for bounded random integers #1172

@ctsrc

Description

@ctsrc

Background

What is your motivation?

I came across this interesting pull request that someone made on the official Swift programming language repository

swiftlang/swift#39143

It makes some very intriguing claims, stating such as:

reduces the worst-case expected number of random bits required from O(log₂(upperBound)) to log₂(upperBound) + O(1), which is optimal

and

this algorithm can be made unconditional by removing the early out, so that every value computed requires word size + 64 bits from the stream, which breaks the loop-carried dependency for fast generators, unlocking vectorization and parallelization where it was previously impossible

And I was wondering if this might similarly be useful in your rand crate

What type of application is this? (E.g. cryptography, game, numerical simulation)

All applications of random number generation. And from what I understand could make SIMD improvements for random number generation possible also?

Feature request

I request that the rand crate authors have a look at this algorithm swiftlang/swift#39143 and that they determine whether it could be implemented into the rand crate to improve performance for the generation of random numbers.

And alternatively, if it is something that needs language support inside of Rust itself. I am not able to determine on my own whether such is the case or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-newPropose usage of a new algorithm

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions