-
Notifications
You must be signed in to change notification settings - Fork 27
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
add random_range functions and code regions #28
base: master
Are you sure you want to change the base?
Conversation
I'm on the toilet but I'm 40% sure randomFloatRange will not work as intended! I spent like 6 hours the other day trying to get this to work so consider this: If you test 1 to 100 a thousand times, I am guessing that 33% of the numbers will be less than 10. That is because when you roll for a random exponent with 1 to 100, it can only be 0, 1, or 2. Each exponent range has a 33% chance to be selected. Therefore... 33% will have an exponent of 0 (less than 10), 33% will have an exponent of 1 (10-99), and 33% will have an exponent of 2 (100-999). Of course, the final thing the function does is normalize(), so it will fix the numbers that are greater than 100! The result is that 66% of numbers are > 10 and 33% are not, when it should be expected that each range of 10 would be 10%. Hope I said that clearly enough! |
Just tested. |
With c01933e, I made it so that if the range being picked from is within 6 decimal places ( Additionally, I added an error check in case someone passes a larger minimum value than the maximum value, reduced the loop presence as a minor optimization, and normalized the result again for That last bit could be improved but with this, |
When done this way, the mantissa can only ever be greater than min.mantissa. I tested 5 to 100, and all of the numbers were either 5 to 10, or 50 to 100. |
I almost feel guilty for dumping this task on your shoulders, lol. You're doing great so far, but it still isn't right! |
Friends, here is the solution for you
|
Setting the exponent using randi_range is incorrect because it does not take into account the mantissa. Say A is 9,000 and B is 90,000. The new exponent has a 50% chance to roll 3, and a 50% chance to roll 4. This leads to an inaccurate representation! It should roll an exponent of 3 1,000 out of 100,000 times, or 1% of the time, unless my math is wrong. This still isn't correct. It needs to incorporate some kind of weight system. I'm going to try to look at it again. |
How about this? This seems like it's finally it! I got the base code from Claude and adjusted until it was right. This is passing all of my tests so far. I'm going to use it in my game until I find anything wrong with it. (By the way, my version of Big is older than the current version, so if y'all want to use this, you will have to adjust it.)
|
randomFloatRange(Big, Big)
andrandomIntRange(Big, Big)
as suggested by @Drillur in Overhaul and overall improvement of GodotBigNumberClass #27