Skip to content

Switch randint(upper_bound) to arc4random_uniform() if available#1754

Open
michaelortmann wants to merge 4 commits into
eggheads:developfrom
michaelortmann:random3
Open

Switch randint(upper_bound) to arc4random_uniform() if available#1754
michaelortmann wants to merge 4 commits into
eggheads:developfrom
michaelortmann:random3

Conversation

@michaelortmann
Copy link
Copy Markdown
Member

@michaelortmann michaelortmann commented Jan 31, 2025

Found by: michaelortmann
Patch by: michaelortmann
Fixes:

One-line summary:
Switch randint(upper_bound) to arc4random_uniform(upper_bound) if available

Additional description (if needed):
Switch also rand() % upper_bound and random() % 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:

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.

Test cases demonstrating functionality (if applicable):

Keep srandom(seed) also if we use arc4random*()

Update doc tcl-commands.rst

Add dietlibc hints to doc COMPILE-GUIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant