Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upFix weighted list RNG on platforms with a different RAND_MAX value #14413
Conversation
remyroy
changed the title
[WIP] Fix weighted list RNG on platforms with different a RAND_MAX value
Fix weighted list RNG on platforms with a different RAND_MAX value
Dec 13, 2015
sparr
reviewed
Dec 13, 2015
| picked = ( double )rand_ll / ( double )INT_MAX * ( this->total_weight ); | ||
| } | ||
| size_t pick_ent( unsigned int randi ) const override { | ||
| double picked = ( double )randi / ( double )RAND_MAX * ( this->total_weight ); |
This comment has been minimized.
This comment has been minimized.
sparr
Dec 13, 2015
Member
double picked = ( double )(randi%RAND_MAX) / ( double )RAND_MAX * ( this->total_weight );
the modulo operation will make sure the picked number is <total_weight, in cases where randi>RAND_MAX because INT_MAX>RAND_MAX (such as on the windows platform where this bug was identified)
This comment has been minimized.
This comment has been minimized.
|
randi should never be greater than RAND_MAX with our current code using weighted_float_list but for completion, I'll make the modification. |
This comment has been minimized.
This comment has been minimized.
|
I would merge this if I could test it on Windows. |
This comment has been minimized.
This comment has been minimized.
|
I now have a headache and a copy of CleverRaven:master with your changes compiling on my Windows 7 64bit system. I'll get back to you with the results soon. |
This comment has been minimized.
This comment has been minimized.
|
Random vehicles appear to only be spawning in cities. I traveled for several dozen map tiles of non-city roads and didn't see a single vehicle. City car levels seem to be at or slightly above the normal levels. I may have had an unlucky run, I will create a new world and try again. Edit: I think I was just unlucky the first time around. Second world had a long stretch of road surrounded by forest, I encountered 2 sports cars along the way, seems good to me. |
remyroy commentedDec 13, 2015
Fixes #14410.