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

Priorities don't matter in rare cases #15

Closed
ndsvw opened this issue Dec 10, 2022 · 1 comment
Closed

Priorities don't matter in rare cases #15

ndsvw opened this issue Dec 10, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@ndsvw
Copy link
Owner

ndsvw commented Dec 10, 2022

SortingBasedWeightedLeftShuffle can't handle a combination of large priorities and large random doubles:

Math.Pow(0.9999, 1/(double)int.MaxValue) // = 0.99999999999995348165526820594095624983310699462891
Math.Pow(0.9999, 1/(double)long.MaxValue) // = 1.00000000000000000000000000000000000000000000000000
Math.Pow(0.9999, 1/((double)long.MaxValue/10)) // = 1.00000000000000000000000000000000000000000000000000
Math.Pow(0.9999, 1/((double)long.MaxValue/1_000_000)) // = 1.00000000000000000000000000000000000000000000000000
Math.Pow(0.9999, 1/((double)long.MaxValue/10_000_000)); // = 0.99999999999999988897769753748434595763683319091797

So, maybe, there needs to be a fallback like Math.Pow(0.9999, 10_000_000/(double)n); for larger numbers.
Maybe, a fallback should already be there for ints, because for ~0,000001% of the weights (higher if we would allow long weights), it does not even make a difference, whether they are int.MaxValue or int.MaxValue / 10 (edge case):

Math.Pow(0.99999999, 1/(double)int.MaxValue) // = 1.00000000000000000000000000000000000000000000000000
Math.Pow(0.99999999, 1/((double)int.MaxValue / 10)) // = 1.00000000000000000000000000000000000000000000000000
Math.Pow(0.99999999, 1/((double)int.MaxValue / 100))  // = 0.9999999999999996

This gets worse when allowing to specify priorities as longs (see #14)


Furthermore: Random.NextDouble being exactly 0 could also be problematic as the result is always 0...


(from #14)

@ndsvw
Copy link
Owner Author

ndsvw commented Dec 10, 2022

Furthermore: Random.NextDouble being exactly 0 could also be problematic as the result is always 0...

Fixed with db3a8ed

@ndsvw ndsvw closed this as completed in e585693 Dec 10, 2022
@ndsvw ndsvw added the bug Something isn't working label Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant