Skip to content

uniform_int_distribution output changed from VS 17.4 to 17.5? #3541

Description

@totalgee

I discovered some of my project's unit tests failed when I moved from VS 17.4 to 17.5, presumably due to a new version of the STL.

After debugging and looking at the code in this repo, I believe this is due to the change #3012, which substituted a faster algorithm (_Rng_from_urng_v2) for uniform_int_distribution. Is there a recommended way to get the old behaviour? We require repeatable (and cross-platform) random number generation for some things, and although our random generator (PCG) is still producing the same sequence of states after the Visual Studio version update, the remapping to our [lo, hi] integer range using uniform_int_distribution is no longer producing the same sequence of numbers.

You probably don't consider this a bug, since I expect the behaviour of this STL class is allowed to be implementation-defined (as long as it produces a statistically uniform distribution)... My workaround for now is basically to use rng() % (hi - lo + 1) + lo, which does at least produce the same integer sequence we had with VS 17.4 and earlier versions (albeit slower).

Thanks for any suggestions (or should I just avoid using uniform_int_distribution if I want cross-platform repeatability?).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedresolvedSuccessfully resolved without a commit

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions