Skip to content

Number operations - .NET 9 behavior change #124379

@paul-barry-delongchamps

Description

This is a simplified expression of a complex code path we found in our code base while migrating to .NET 10:
(uint)(((double)random.Next() + (uint)random.Next()) * random.Next())

This always returns the same magic number in .NET 9 and later version whatever the Random instance used: 4294967295. It returns random results in .NET Framework or .NET Core until version 8.

We found that by chance and will workaround it on our own. I guess the same returned value is caused by a sequence of casts, but I was curious as to why the behavior changed in .NET 9. Please tell me if this is not the right place for this question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.NumericsquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions