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

Fix weighted list RNG on platforms with a different RAND_MAX value #14413

Merged
merged 2 commits into from Dec 15, 2015

Conversation

Projects
None yet
4 participants
@remyroy
Copy link
Contributor

commented Dec 13, 2015

Fixes #14410.

@remyroy 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

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.

Copy link
@sparr

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)

@remyroy

This comment has been minimized.

Copy link
Contributor Author

commented Dec 13, 2015

randi should never be greater than RAND_MAX with our current code using weighted_float_list but for completion, I'll make the modification.

@sparr

This comment has been minimized.

Copy link
Member

commented Dec 13, 2015

I would merge this if I could test it on Windows.

@Malkeus

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2015

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.

@Malkeus

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2015

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.

@kevingranade kevingranade merged commit 6c1a861 into CleverRaven:master Dec 15, 2015

1 check passed

default This has been rescheduled for testing as the 'master' branch has been updated.

@remyroy remyroy deleted the remyroy:fix-weighted-list-rng branch Dec 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.