[RFC]: expand support for additional pseudorandom number generators #136
Labels
2025
2025 GSoC proposal.
received feedback
A proposal which has received feedback.
rfc
Project proposal.
Full name
Abdul Kaium
University status
Yes
University name
Jahangirnagar University
University program
Computer Science and Engineering
Expected graduation
January 2027
Short biography
I'm a 3rd year undergraduate student of Computer Science & Engineering at Jahangirnagar University, Dhaka, Bangladesh. I've been coding from an early age sparked by a deep curiosity about computers and software, starting with C. Now, I’m proficient in C++ and JavaScript, with experience in several other programming languages. I have a strong passion for competitive problem solving, algorithmic optimizations, GPU computation, and color science.
Timezone
Bangladesh Standard Time (UTC+06:00)
Contact details
email: [email protected], github: impawstarlight
Platform
Linux
Editor
I prefer VSCode for its rich set of features, built-in Git integration, and extensive support for extensions. The editor’s versatility and customizability make it an excellent choice for various projects, whether it's competitive programming, web development, or system-level work. Its fast performance and portability across different platforms also add to its appeal, making it my go-to tool for coding.
Programming experience
My programming journey began in 2017 with C, driven by personal curiosity. I initially used it to solve math homework, find large prime numbers, calculate large factorials, and explore other number-related hobbies. Later that year, I learned C++ and Java to understand object-oriented programming, but I didn't use them much at that time. In 2021, I started learning Javascript (along with HTML and CSS), which opened up a whole new world of possibilities, allowing me to build GUI applications for the first time.
Over the next two years, I focused heavily on vanilla JavaScript, building various mini-projects. My most significant project is Chromania, a color picker and namer tool that supports advanced color spaces like CIELAB and Oklab. Another project worth mentioning is BRUHsimp, an very basic algebraic expression processor for expanding and simplifying moderately complex expressions, which I created to aid my work on Chromania.
For much of this journey, I was coding on a mobile phone due to lack of access to a computer. This limitation sparked my interest in performance optimization techniques, as I had to compensate for the limited processing power of my device.
After enrolling in university in 2023, I started competitive programming (with C and later transitioned to C++), which I found incredibly satisfying as it aligned with my love for math, problem-solving and optimization. I’m currently an Expert on Codeforces and an active participant in nation-wide inter-university programming contests.
JavaScript experience
JavaScript is my go-to language for personal projects, and it's the language I'm most comfortable with. I’ve worked primarily with vanilla JavaScript, handling everything from DOM manipulation to creating complex algorithms manually.
The best part of JavaScript for me is its portability across different devices along with its ability to easily create GUI applications which made it accessible to me even without a computer, and helped me dive deep into programming.
On the downside, I find JavaScript's lack of static typing a bit limiting, especially for larger projects, and its inability to handle 64-bit integer arithmetic natively is something I wish it had.
Node.js experience
I’ve briefly explored Node.js while experimenting with frontend frameworks like React and Svelte, and backend technologies like Express. One fun project I built with Node.js is a Rock-Paper-Scissors game with WebSockets, where two users can play and chat online. I hosted it locally using an ngrok free-tier domain, which gave me hands-on experience with real-time communication between clients and servers.
C/Fortran experience
C was my first programming language, and I’ve spent a significant amount of time with it, particularly for competitive programming. I’m very comfortable with its core concepts, including pointers, dynamic memory management, and meta-programming.
As for Fortran, although I had no prior experience, I’ve looked into some Fortran code and found it relatively accessible, especially when using it as a reference for C or JavaScript implementations. I plan to learn more about Fortran during the community bonding period to better understand its application in scientific computing.
Interest in stdlib
stdlib
stands out as a powerful JavaScript alternative to Python’s Numpy, offering efficient utilities for data manipulation, statistical analysis, mathematical computations, and more, all with a clean and modular design. I’m fascinated by its motivation and design principles, and I’m excited about the opportunity to be a part of this wonderful project that has the potential to become "The Standard Library" for high-performance, advanced mathematical computation in JavaScript.My favorite feature of stdlib is its REPL environment which helped me a lot with debugging while working on my PRNG implementations as it enables us to quickly run stdlib functions from the command line. Another thing I particularly appreciate about stdlib is its large collection of assertion and utility functions that help keep the codebase clean and meaningful.
Version control
Yes
Contributions to stdlib
I have successfully contributed to
stdlib
with simple patches as well as complex features that are directly related to this project.Merged PRs:
random/base/minstd
stdlib#6498Open PRs:
random/base/xorshift32
stdlib#6333random/base/pcg32
stdlib#6551All PRs:
stdlib showcase
Simulations with random numbers
Goals
The goal of this project is to add Javascript and C implementations of at least 12 and upto 20 new pseudorandom number generators to the
@stdlib/random
namespace. The large uncertainty gap in the expected number of new PRNGs is due to the following facts:Hopefully, these confusions will be resolved as the project progresses, resulting in the implementation of a significantly greater number of PRNGs than the minimum specified above. Hence, I'm fairly optimistic that the actual number will be closer to 20 at the end of this project.
Primary Goals
The primary goal consists of implementing 12 new PRNGs in
@stdlib/random/base
along with additional higher-level wrappers (array
,iter
, etc.) for each of them. The proposed PRNGs are chosen with a careful evaluation of their statistical propety, performance, historical relevance, and implementation difficulty in Javascript. These are the ones that I've explored in detail and judged to be relevant and readily implementable instdlib
. All the proposed PRNGs below will have 32-bit outputs unless otherwise specified. Additionally, a key focus throughout the project will be on finding an overall best general purpose PRNG among the implemented ones that can serve as the new default PRNG instdlib
.PCG-XSH-RR 64/32:
Permuted Congruential Generator, uses a simple Linear Congruential Generator under the hood but applies an ouput permutation to improve randomness quality. The XSH-RR variant is the most widely used one for producing 32-bit outputs.
PCG-RXS-M-XS 32/32:
A reduced state variant of the PCG family for use when the state size must be limited to 32-bit. It's a faster alternative to the XSH-RR variant with a small compromise on the statistical quality.
Philox-4x32-10:
A counter-based PRNG from the Random123 suite, designed for parallel computation. The 4x32-10 variant is the standard, using four 32-bit words and 10 rounds of Feistel-like mixing.
Squares (32-bit):
A counter-based PRNG that applies multiple rounds of squaring to a counter, based on the concept of von Neumann's middle-square method.
Xorshift (32-bit):
Xorshift is a family of simple and efficient PRNGs that uses only bitwise XORs and shifts to generate pseudo-random numbers. The 32-bit variant has a small state size and is widely used for applications requiring fast and reasonably good random numbers.
Xorwow:
Xorwow is an extension of the Xorshift family that enhances randomness quality by incorporating an additional mixing step.
WELL512a:
The smallest variant of the WELL (Well Equidistributed Long-period Linear) family of PRNGs, designed to improve upon the weaknesses of Mersenne Twister.
WELL1024a:
A higher-capacity variant of the WELL family with improved period and statistical strength, suitable for applications needing large state spaces.
MRG32k3a:
A Combined Multiple Recursive Generator by Pierre L’Ecuyer, designed for high-quality, long-period pseudo-random number generation.
rstream
).Taus88:
A maximally equidistributed combined Tausworthe generator that combines 3 LFSRs to yield a reasonably good PRNG with moderate period.
LFSR113:
An improved variant of the maximally equidistributed combined Tausworthe generators developed by L'Ecuyer, which combines 4 LFSRs.
Wichmann–Hill:
A combined linear congruential generator combining the outputs of three independent LCGs with prime moduli, yielding double precision floating point values in the interval [0,1).
Stretch goals:
In case the aforementioned goals are successfully completed way before the project deadline and there's ample time to spare, the following objectives might be persued to further improve the
@stdlib/random
libray:Why this project?
Random number generation has always intrigued me, especially the idea that deterministic algorithms can produce seemingly random outputs feels like a paradox. This project offers a perfect opportunity to dive deep into the intricacies of PRNGs and explore how they are designed and optimized. The algorithmic challenges involved in implementing various PRNGs excite me, as they remind me of tackling problems in competitive programming where efficiency and precision are of utmost importance. I’m eager to contribute to this project and deepen my understanding of a critical area of computer science that has broad applications in fields like cryptography, simulations, and gaming.
Qualifications
As a competitive programmer, I have solid experience with algorithmic analysis, bit manipulation and modular arithmetic which are core concepts in PRNG algorithms and that makes this project a natural fit for me. Additionally, I’ve completed academic courses like Algorithms and Data Structures, Discrete Mathematics, and Digital Logic Design, giving me a strong foundation in computational principles.
I’ve also demonstrated my familiarity with the stdlib codebase and PRNG internals by contributing two new PRNG implementations, which are awaiting approval and I’m currently studying research papers by various PRNG designers to understand the core ideas behind their algorithms.
Prior art
The core idea behind this project is well-established in other ecosystems. Python’s random module, NumPy’s Generator and BitGenerator classes, and C++’s header all offer a variety of PRNGs with different tradeoffs in speed, space, and statistical quality. Libraries like rand in Rust or Random123 (from D.E. Shaw Research) take it even further, with a focus on modern, parallel-friendly designs.
Most of the PRNGs proposed in this project have accompanying papers which are listed below:
Additional papers that are useful for this project are listed below:
Useful books:
Commitment
I plan to invest ~30 hr/week on average during the GSoC period for a total of 350 hours. I have no other commitments during this period, which allows me to fully dedicate my time to this project.
Schedule
Assuming a 12 week schedule, here is a draft schedule for realizing the project goals.
Community Bonding Period: Preparation
stdlib
development protocol and ensure proper setup of the development environment.Week 1: Xorshift (32-bit) and Xorwow
random/base/xorshift32
package that is currently awating review.Potential candidates include Xorshift+, Xoshiro and Xoroshiro family of PRNGs.
Week 2: PCG-XSH-RR 64/32 and PCG-RXS-M-XS 32/32
random/base/pcg32
package that is currently awating review.One potential candidate is PCG-RXS-M-XS 64/64 which has the potential to be the overall best PRNG for 53-bit output in
stdlib
despite requiring 64-bit arithmetic, but further research is needed on this.Week 3: Philox-4x32-10
Week 4: Squares (32-bit)
Week 5: WELL512a and WELL1024a
Week 6: Midterm Review
Week 7: MRG32k3a
Week 8: Taus88, LFSR113 and Wichmann-Hill
Week 9: Higher-Level Wrappers
random/array
,ranodm/iter
,ranodm/streams
andranodm/strided
.Week 10: A New Default
Week 11: Code Freeze
Week 12: Final Review and Wrap-up
Final Week:
Notes:
Related issues
Checklist
[RFC]:
and succinctly describes your proposal.The text was updated successfully, but these errors were encountered: