Skip to content

Generate random doubles: net11.0, uniform secure double, real tests - #2407

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/61516-csharp-random-double-range
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/61516-csharp-random-double-range

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Moves numbers-csharp/GenerateRandomDoubles to net11.0 and fixes GetSecureDouble, which divided 1 by a random integer and so returned values piled up next to zero; it now divides a secure integer from RandomNumberGenerator.GetInt32(int.MaxValue) by int.MaxValue, giving evenly spread values in [0, 1). It also switches to Random.Shared, drops the unused RandomNumberGenerator.Create() call and redundant casts, adds GetPseudoDoubleBelowUpperBound and GetPseudoDoubleWithinWideRange, makes Main run once with the article's values instead of a prompt loop that crashed on empty input, and replaces four tests that only checked IsNotNull with eight tests covering the intervals, the spread of the secure double and the rounding and overflow edge cases (MSTest 4.5.3, Microsoft.NET.Test.Sdk 18.12.0, coverlet.collector 10.1.0).

… real tests

Fix GetSecureDouble to divide a secure integer by int.MaxValue instead of
dividing 1 by it, drop the unused RandomNumberGenerator.Create() call and the
redundant casts, use Random.Shared, add the below-upper-bound and wide-range
helpers, run Main once with the article's values, and replace the four
IsNotNull tests with eight tests that check intervals, spread and the
rounding edge cases. MSTest 4.5.3, Microsoft.NET.Test.Sdk 18.12.0,
coverlet.collector 10.1.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant