Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random DateTime will never return its maximum bounds #2

Open
sunjay opened this issue Jan 20, 2016 · 0 comments
Open

Random DateTime will never return its maximum bounds #2

sunjay opened this issue Jan 20, 2016 · 0 comments

Comments

@sunjay
Copy link

sunjay commented Jan 20, 2016

Hi,
Please correct me if I'm understanding this incorrectly, but I believe the code here will never return any values in the upper bounds of its Next() calls.

Data.cs#L51

return new DateTime(Number.Next(1900, 2100), Number.Next(1, 12), Number.Next(1, 29), Number.Next(1,24), Number.Next(0,59), Number.Next(0,59));

Number.Next() is defined as below:

public static int Next(int min, int max)
{
  return _rnd.Next(min, max);
}

Where _rnd is an instance of System.Random. According to the documentation for Random.Next:

A 32-bit signed integer greater than or equal to minValue and less than maxValue; 
that is, the range of return values includes minValue but not maxValue. If minValue
equals maxValue, minValue is returned.

So by using 2100, 12, 24, 59 and 59 as max values, none of those values will ever be reached. This dramatically reduces the available distribution of this method. (So does using 29 but that's a separate issue.)

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

No branches or pull requests

1 participant