Skip to content

Random.Next(int,int) can return out-of-bounds result in .NET 6 Preview 2 #50911

Closed

Description

@koszeggy

Description

My UnitTests revealed the following bug when targeting .NET 6 Preview 2:

The Random(int,int) method can return invalid results.

The following example has about 50% chance to return a huge negative value:

int i = new Random().Next(-1, Int32.MaxValue);

Configuration

Reproducible with .NET 6 Preview 2

Other information

The bug is reproducible only if there is no seed specified so the new XoshiroImpl is created internally.

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Apr 8, 2021
  2. self-assigned this
    on Apr 8, 2021
  3. added and removed
    untriagedNew issue has not been triaged by the area owner
    on Apr 8, 2021
  4. added this to the 6.0.0 milestone on Apr 8, 2021
  5. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Apr 8, 2021
  6. stephentoub commented on Apr 8, 2021

    @stephentoub
    Member

    Thanks for the bug report. Fix is in #50922.

  7. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Apr 11, 2021
  8. ghost locked as resolved and limited conversation to collaborators on May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions