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

Optimize ALFG for 32-bit systems and improve initialization #623

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Knogle
Copy link
Contributor

@Knogle Knogle commented Oct 25, 2024

The algorithm wasn't complying with standards, and was a substractive and not additive algorithm. This has been fixed now, as well as some minor optimizations to the efficiency for 32-bit legacy machines.

  • Refactored the Additive Lagged Fibonacci Generator (ALFG) to optimize performance on 32-bit systems.
  • Replaced 64-bit operations with 32-bit (uint32_t) for faster computation on 32-bit architectures.
  • Implemented bitmasking (& MASK) to enforce 32-bit overflow and efficient modulo operations, reducing the need for costly arithmetic operations.
  • Enhanced initialization: Added support for user-provided initialization keys, splitting each 64-bit key into two 32-bit values to populate the state array.
  • Improved fallback seeding using a Linear Congruential Generator (LCG) to initialize the state if the provided key is insufficient.
  • Structured comments for clarity and maintenance.

These changes make the ALFG faster on 32-bit systems while preserving its long period and statistical properties for non-cryptographic applications.

- Refactored the Additive Lagged Fibonacci Generator (ALFG) to optimize performance on 32-bit systems.
- Replaced 64-bit operations with 32-bit (`uint32_t`) for faster computation on 32-bit architectures.
- Implemented bitmasking (`& MASK`) to enforce 32-bit overflow and efficient modulo operations, reducing the need for costly arithmetic operations.
- Enhanced initialization: Added support for user-provided initialization keys, splitting each 64-bit key into two 32-bit values to populate the state array.
- Improved fallback seeding using a Linear Congruential Generator (LCG) to initialize the state if the provided key is insufficient.
- Structured comments for clarity and maintenance.

These changes make the ALFG faster on 32-bit systems while preserving its long period and statistical properties for non-cryptographic applications.
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