Switch randint(upper_bound) to arc4random_uniform() if available #1754
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Found by: michaelortmann
Patch by: michaelortmann
Fixes:
One-line summary:
Switch
randint(upper_bound)
toarc4random_uniform(upper_bound)
if availableAdditional description (if needed):
Switch also
rand() % upper_bound
andrandom() % upper_bound
This PR not only enables good random numbers within eggdrop, but also cleans up a lot of legacy and fragile code (behind ifdefs for systems that dont have arc4random)
A bit of recent history:
arc4random()
based ongetrandom()
invDSO
https://www.phoronix.com/news/Linux-getrandom-vDSOarc4random()
Finally all major operating systems and libcs support it, even cygwin, dietlibc and musl.
arc4random_*() became the defacto standard for (secure) random numbers.
While at it, i added 2 dietlibc hints to COMPILE-GUIDE.
Please run
misc/runautotools
when testing / merging this PR.Test cases demonstrating functionality (if applicable):