Skip to content

Random.Decimal with min = 0, max = decimal.MaxValue overflows #319

@Tvel

Description

@Tvel

Version Information

Software Version(s)
Bogus NuGet Package 30.0.3
.NET Core? 3.1
.NET Full Framework?
Windows OS? 10
Linux OS?
Visual Studio?

What locale are you using with Bogus?

en-us

What is the expected behavior?

before v30 faker.Random.Decimal(0m, decimal.MaxValue) returned a value.

What is the actual behavior?

System.OverflowException
Value was either too large or too small for a Decimal.
at System.Number.ThrowOverflowException(TypeCode type)
at System.Decimal.DecCalc.ScaleResult(Buf24* bufRes, UInt32 hiRes, Int32 scale)
at System.Decimal.DecCalc.VarDecMul(DecCalc& d1, DecCalc& d2)
at System.Decimal.op_Multiply(Decimal d1, Decimal d2)
at Bogus.Randomizer.Decimal(Decimal min, Decimal max)

Can you identify the location in Bogus' source code where the problem exists?

https://github.com/bchavez/Bogus/blob/master/Source/Bogus/Randomizer.cs#L195
As I understand there was a change in the randomiser to make double values more precise.

If the bug is confirmed, would you be willing to submit a PR?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions