Skip to content

[RFC]: Expand support for additional pseudorandom number generators #114

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

Open
7 tasks done
abdelrahman04 opened this issue Mar 24, 2025 · 3 comments
Open
7 tasks done
Labels
2025 2025 GSoC proposal. received feedback A proposal which has received feedback. rfc Project proposal.

Comments

@abdelrahman04
Copy link

abdelrahman04 commented Mar 24, 2025

Full name

Abdelrahman Osman

University status

Yes

University name

German International University

University program

Software Engineering, Computer Science

Expected graduation

June, 2026

Short biography

I am a third-year top-ranked undergraduate Software Engineering student with a strong passion for algorithms, system design, and backend development. I thrive at the intersection of software engineering, numerical computing, and machine learning, always seeking to optimize and build efficient systems.

My experience spans full-stack development (Node.js, Nest.js, Next.js, Prisma), machine learning pipelines (CNNs, Transformers, LLaMA models), and competitive programming (Candidate Master on Codeforces). I’ve developed scalable backend services, contributed to open-source projects, and mentored students in problem-solving and software development.

Previously, I interned at Microsoft, where I worked on data pipelines, model training, and deep learning architecture. I also built a secure web-based platform for multi-party secret communication and developed high-performance gaming applications in Java.

For GSoC, I’m excited to contribute to the stdlib JavaScript library, expanding support for pseudorandom number generators. This project aligns perfectly with my interests in efficient algorithms, numerical computing, and open-source development—and I look forward to making a meaningful impact.

Timezone

Eastern European Time

Contact details

email:[email protected], github:abdelrahman04

Platform

Windows

Editor

I prefer VS Code as it's portable easy to navigate through different languages and easier to build projects.

Programming experience

In my programming journey, I have explored various domains, including competitive programming, software development, and backend engineering. I enjoy solving complex problems, optimizing systems, and building efficient applications.

I'm actively engaged in competitive programming, holding the Candidate Master rank on Codeforces, where I primarily use C++ to tackle algorithmic challenges. My problem-solving skills have also helped me mentor students in data structures, algorithms, and competitive programming techniques.

Beyond competitive programming, I have a strong background in backend and full-stack development, working with Node.js, Nest.js, Next.js, and Prisma. Some of my favorite projects include:

  • MultiParty Secret Communication – A secure web-based platform that enables agents to share locations without revealing their actual positions, leveraging mp-speadz for cryptographic privacy.
  • Abo Alaraby (E-commerce Platform) – A full-stack React.js, Node.js, and MongoDB web application featuring secure authentication, payment processing, and automated testing using Jest & Cypress.
  • Tutor Flow – A full Udemy clone built with MongoDB, Nest.js (backend), and Next.js (frontend).
  • Abdelrahman_Osman_Resume.pdf

JavaScript experience

I have extensive experience with JavaScript and TypeScript, particularly in backend and full-stack development. I’ve built applications using Node.js, Nest.js, Next.js, and Prisma, focusing on scalability, performance, and security. My work includes designing RESTful APIs, GraphQL backends, and microservices architectures.

One of my notable projects is Abo Alaraby, an e-commerce platform built with React.js, Node.js, Express.js, and MongoDB, implementing secure authentication, payment processing, and automated testing. I also designed and deployed a secure multi-party communication platform using Nest.js and GraphQL.

Favorite Feature of JavaScript:
One of my favorite features is asynchronous programming with Promises and async/await. It allows for cleaner, more readable asynchronous code, making it easier to manage network requests, database calls, and parallel processing. The event loop and non-blocking nature of JavaScript make it highly efficient for web applications.

Least Favorite Feature of JavaScript:
My least favorite feature is the quirks of type coercion and weak typing. Implicit conversions, such as "5" - 1 resulting in 4 but "5" + 1 resulting in "51", can lead to unexpected bugs. This is why I prefer TypeScript for large-scale applications—it provides strong typing and better tooling while maintaining JavaScript’s flexibility.

Node.js experience

I have extensive experience with Node.js, primarily in backend and full-stack development. I’ve built scalable web applications, RESTful APIs, and GraphQL services using Node.js and frameworks like Nest.js, Express.js, and Next.js shown in projects above.

C/Fortran experience

I have experience with C, particularly in systems programming, low-level optimization, and competitive programming. While my primary languages are C++, Java, and Python, I have used C in various projects and problem-solving scenarios:

Systems Programming & Low-Level Development:

  • Familiar with pointers, memory management (malloc/free), and data structures like linked lists, trees, and hash tables.
  • Experience with bitwise operations, file handling, and multithreading using POSIX threads (pthreads).

Competitive Programming:

  • Occasionally use C for performance-critical problems in Codeforces and ICPC contests due to its low-level control and efficiency.
  • Optimized solutions using manual memory management and reduced overhead operations.

Embedded & Performance-Oriented Code:

  • Familiar with writing efficient, memory-safe code for constrained environments.
  • Used C for interfacing with low-level system calls and optimizing execution time.

Interest in stdlib

What excites me about stdlib is its focus on high-performance numerical computing and scientific utilities for JavaScript. As someone passionate about efficient algorithms, backend optimization, and numerical computing, I see stdlib as a crucial library for making JavaScript more powerful in scientific applications, statistics, and data processing.

I particularly appreciate how stdlib bridges the gap between JavaScript and high-performance computing, providing tools for random number generation, statistical functions, and matrix operations—features that are typically found in languages like Python (NumPy) or C++.

Favorite Feature: Random Number Generators (RNGs)
One of my favorite aspects of stdlib is its extensive collection of pseudorandom number generators (PRNGs). The ability to control randomness, ensure reproducibility, and select from various distributions is essential in fields like Monte Carlo simulations, machine learning, and game development.

Version control

Yes

Contributions to stdlib

Merged PR’s
Includes solving some linting errors and adding a few fixes

Open PR’s
Includes adding new PRNG packages that need to get approved.

Issues

stdlib showcase

As a showcase project, [stdlib-random](https://stdlib-showcase-one.vercel.app/) is a web application that demonstrates the capabilities of the stdlib library's random number generators. This project leverages @stdlib/random to generate random numbers from various distributions, visualize their distributions, and provide sample code for each generator. Additionally, it includes a terminal interface displaying generated random numbers in real-time. My showcase project aims to provide developers with practical insights into utilizing these PRNGs effectively, thereby enhancing their applications with reliable and efficient random number generation.

Goals

Currently, the library offers limited options for PRNGs. This project proposes adding 8 new algorithms (TinyMT64, Xorshift-Add, PCG-XSL-RR, Middle-square Weyl Sequence, WELL1024, RANLUX, Tausworthe (Taus2), and Jenkins Small Fast (JSF)) to provide developers with a wider range of choices depending on their specific needs.

This project has the potential to significantly enhance the https://github.com/StdLib\random library, providing developers with a broader spectrum of high-performance, statistically sound PRNG

All module to be implemented will be similar in structure to @stdlib/random/base/mt19937

Below is a comparative analysis for all PRNGs:

TinyMT64

Strengths:

  • A lightweight alternative to Mersenne Twister, designed for small-state applications.
  • Provides high statistical quality despite a smaller state size.
  • Faster initialization compared to the original MT19937.
  • Well-suited for simulations and general-purpose applications.

Limitations:

  • Not cryptographically secure.
  • Has a shorter period than standard Mersenne Twister variants, which may limit its use in some applications.

Generation Range:

  • Produces 32-bit or 64-bit integers (depends on implementation).
  • Can be scaled to [0,1) floating-point values.

Xorshift-Add

Strengths:

  • Extremely fast due to the simplicity of XOR shifts and addition.
  • Requires minimal memory, making it suitable for performance-critical applications.
  • Passes many statistical randomness tests with relatively low computational cost.

Limitations:

  • While it performs well in practice, it does not have the strongest theoretical guarantees of randomness.
  • Not cryptographically secure.
  • Can exhibit weaknesses in low-dimensional distributions.

Generation Range:

  • Typically outputs 32-bit or 64-bit integers.
  • Can be mapped to floating-point values in the range [0,1).

PCG-XSL-RR

Strengths:

  • Excellent randomness properties, passing many empirical statistical tests.
  • More uniform output distribution compared to linear congruential generators (LCGs).
  • High-quality randomness with efficient memory usage.
  • Provides reproducibility and supports different period lengths for flexibility.

Limitations:

  • Not cryptographically secure.
  • As a relatively newer PRNG family, it has not been as widely used as older methods like Mersenne Twister.

Generation Range:

  • Outputs 32-bit or 64-bit integers.
  • Can be transformed into floating-point values in [0,1).

Middle-square Weyl Sequence

Strengths:

  • Improves upon the classic Middle-square method by adding Weyl sequence updates, preventing rapid cycles.
  • Simple and easy to implement.
  • Can be adapted for high-performance computing and parallelized workloads.

Limitations:

  • Can still suffer from short cycles if not initialized properly.
  • Requires careful selection of parameters to avoid poor randomness properties.
  • Not cryptographically secure.

Generation Range:

  • Produces 32-bit or 64-bit integers depending on implementation.
  • Can be scaled to [0,1) floating-point numbers.

WELL1024

Strengths:

  • A significant improvement over Mersenne Twister in terms of statistical quality and equidistribution.
  • Reduces state size while maintaining a long period, making it more memory-efficient.
  • Suitable for Monte Carlo simulations and scientific computing.

Limitations:

  • More complex than Xorshift or PCG variants.
  • Not cryptographically secure.
  • Slower initialization compared to simpler PRNGs.

Generation Range:

  • Typically outputs 32-bit or 64-bit integers.
  • Can be converted into floating-point values in [0,1).

RANLUX

Strengths:

  • Offers superior randomness quality with minimal correlation, making it ideal for scientific simulations.
  • Based on the concept of "luxury levels," allowing adjustable randomness guarantees.
  • Known for its use in physics simulations, including Monte Carlo methods.

Limitations:

  • Computationally expensive compared to faster PRNGs like Xorshift.
  • Higher memory requirements due to the storage of additional state variables.
  • Not suitable for cryptographic purposes.

Generation Range:

  • Typically produces 24-bit or 32-bit values.
  • Can be mapped to floating-point values in [0,1).

Tausworthe (Taus2)

Strengths:

  • Efficient and lightweight, making it ideal for high-speed random number generation.
  • A well-known generator used in high-performance computing applications.
  • Produces high-quality randomness while maintaining a small memory footprint.

Limitations:

  • Can exhibit weak lower bits if not properly implemented.
  • Requires careful seeding to avoid poor sequences.
  • Not cryptographically secure.

Generation Range:

  • Produces 32-bit or 64-bit integers.
  • Can be converted into floating-point values in [0,1).

Jenkins Small Fast (JSF)

Strengths:

  • Optimized for speed while maintaining good statistical properties.
  • Compact state representation, making it ideal for memory-constrained environments.
  • Passes various statistical tests despite its simplicity.

Limitations:

  • Does not offer the strongest statistical guarantees compared to WELL or PCG.
  • Period length is smaller than some of the other advanced generators.
  • Not cryptographically secure.

Generation Range:

  • Typically produces 32-bit integers.
  • Can be transformed into floating-point values in [0,1).

Why this project?

Random number generation is a fundamental component of many applications, from simulations and gaming to scientific computing and machine learning. Enhancing the stdlib JavaScript library with efficient and diverse PRNGs is an exciting opportunity to contribute to a widely used open-source project, impacting a broad developer community.

I have a strong background in algorithms, software development, and performance optimization, and I am particularly fascinated by how different PRNGs balance speed, statistical quality, and memory efficiency. This project offers a unique challenge—implementing PRNGs efficiently in JavaScript while ensuring backward compatibility and robust performance.

Additionally, working on this project allows me to deepen my expertise in numerical computing and random number generation, refining my ability to implement and analyze PRNGs while ensuring their correctness and efficiency. I am eager to apply my skills in low-level optimizations, state management, and algorithm design to enhance stdlib and contribute to the broader open-source ecosystem.

Qualifications

I am well-equipped to execute this proposal due to my strong background in algorithms, software engineering, and numerical computing. My experience includes competitive programming, software development, and deep learning, all of which have strengthened my ability to analyze and implement efficient algorithms.

Relevant Experience:

  • Implemented TinyMT32 in stdlib → This gave me hands-on experience with the codebase, understanding its structure, PRNG state management, and testing framework.
  • Competitive Programming (Candidate Master on Codeforces) → I have worked extensively with randomized algorithms, modular arithmetic, and bitwise operations, which are crucial for efficient PRNG implementations.
  • Software Development & Performance Optimization → I have worked on multiple projects requiring high-performance computation, stateful processing, and efficient memory usage, all relevant for implementing PRNGs.
  • Deep Learning & Data Processing (Internship at Microsoft) → Gained experience in handling large-scale numerical computations and randomness in AI models.
  • MultiParty Communication Project that focuses on security parts of applications.

Theoretical Knowledge:

  • Studied probability theory, discrete mathematics, number theory,, which are foundational for understanding PRNG algorithms.
  • Familiar with bitwise transformations, modular arithmetic, and linear congruential methods, all essential for designing PRNGs.
  • Experience analyzing statistical properties of PRNGs to ensure uniformity and lack of correlation.

Why I am a strong fit?

I already have a head start by implementing TinyMT32, which means I am familiar with stdlib’s PRNG structure, state handling, and API design. My mix of theoretical understanding and practical coding skills makes me well-suited to contribute efficient, well-tested, and scalable PRNG implementations.

Prior art

The PRNGs proposed in this project are supported by foundational research or implementations:​

TinyMT64: A lightweight variant of the Mersenne Twister, offering a balance between speed and statistical quality. ​.

Xorshift-Add (XSadd): Enhances Marsaglia's xorshift generators by adding an additive component to improve randomness quality. ​

PCG32: Part of the Permuted Congruential Generator family, known for simplicity, speed, and excellent statistical properties. ​

WELL (Well Equidistributed Long-period Linear) PRNG: Designed to improve upon the Mersenne Twister with better equidistribution and recovery from zero-excess states. ​

RANLUX: Emphasizes high-quality randomness suitable for Monte Carlo simulations, based on a chaotic dynamical system.

Squares RNG: A modern take on the middle-square method, providing fast and reliable random number generation. ​
arXiv

Middle-Square Weyl Sequence (MSWS): Combines the middle-square method with a Weyl sequence to eliminate weaknesses of the original approach. ​

Tausworthe Generator (Taus88/Taus2): Utilizes linear feedback shift registers to produce sequences with good statistical properties.

Commitment

I don't have any commitments in the summer so I am able to work full time for the whole period
I just have finals in June from 15 to 26, However this will not impact my performance nonetheless.
so I am able to commit to ~30+ hr/week.

Schedule

Assuming a 12 week schedule,
Here’s a well-structured 12-week schedule for implementing the chosen 8 PRNGs in stdlib, ensuring a balance between implementation, testing, and documentation.

Community Bonding Period

  • Deep dive into PRNGs, especially focusing on the 8 selected generators.
  • Study stdlib's existing PRNG implementations and coding style.
  • Set up the initial structure for stream, iter, array, and strided wrappers.
  • Discuss implementation details and possible challenges with mentors.

Week 1: Implement TinyMT64

  • Implement TinyMT64, ensuring correctness and compatibility with stdlib's structure.
  • Write test cases to verify statistical quality and randomness properties.
  • Document implementation details and challenges.

Week 2: Implement Xorshift-Add

  • Implement Xorshift-Add (XSadd) PRNG.
  • Compare with existing Xorshift variants in terms of efficiency and randomness.
  • Perform initial performance testing and optimizations.

Week 3: Implement PCG32

  • Implement PCG32, one of the most widely used non-cryptographic PRNGs.
  • Verify statistical properties using tests.
  • If time permits, explore jump-ahead features.

Week 4: Implement WELL PRNG (WELL512 or WELL1024)

  • Implement a WELL PRNG variant, ensuring adherence to the original design.
  • Compare its performance and randomness properties with other generators.
  • Test its efficiency in different use cases.

Week 5: Implement RANLUX (High-Quality Randomness)

  • Implement RANLUX, focusing on luxury levels and efficiency.
  • Conduct in-depth testing for period length and uniformity.
  • Compare with existing high-quality generators in stdlib.

Week 6: Midterm Evaluation & Optimization

  • Review and refine previous implementations based on feedback.
  • Optimize the existing PRNGs for performance.
  • Finalize documentation for the first 5 PRNGs.

Week 7: Implement Squares RNG

  • Implement Squares RNG, ensuring it adheres to the intended algorithm.
  • Test against other non-linear PRNGs to ensure randomness properties.

Week 8: Implement Middle-Square Weyl Sequence (MSWS)

  • Implement Middle-Square Weyl Sequence (MSWS).
  • Conduct randomness tests and analyze bias if any.
  • Optimize state management for efficient usage.

Week 9: Implement Tausworthe Generator (Maximally Equidistributed)

  • Implement Tausworthe PRNG (Taus/ Taus2), ensuring correctness.
  • Compare statistical properties with WELL and PCG.
  • Ensure compatibility with existing PRNG APIs.

Week 10: Add Stream, Iter, Array, and Strided Wrappers

  • Extend implementations to support stream, iter, array, and strided variants.
  • Test edge cases and performance for each wrapper.

Week 11: Final Testing and Benchmarking

  • Perform final statistical testing for all 8 PRNGs.
  • Benchmark against existing stdlib PRNGs to analyze performance improvements.
  • Fix any remaining issues based on mentor feedback.

Week 12: Documentation & Final Refinements

  • Write detailed documentation for each PRNG.
  • Finalize implementation and conduct code cleanup.
  • Prepare a comprehensive report summarizing findings, comparisons, and optimizations.

Final Week: Submission & Post-Evaluation

  • Submit the final pull requests for each PRNG.
  • Address final mentor feedback.
  • If time permits, explore additional minor improvements or new PRNG candidates.

Potential Extension

  • If time permits and all initial implementations are complete and stable by Week 10–11, up to four additional PRNGs may be added. Candidates include:
    -- Fishman18
    -- Tausworthe (Taus88/Taus2)
    -- RANMAR
    -- VAX Generator

Notes:

  • The community bonding period is a 3 week period built into GSoC to help you get to know the project community and participate in project discussion. This is an opportunity for you to setup your local development environment, learn how the project's source control works, refine your project plan, read any necessary documentation, and otherwise prepare to execute on your project project proposal.
  • Usually, even week 1 deliverables include some code.
  • By week 6, you need enough done at this point for your mentor to evaluate your progress and pass you. Usually, you want to be a bit more than halfway done.
  • By week 11, you may want to "code freeze" and focus on completing any tests and/or documentation.
  • During the final week, you'll be submitting your project.

Related issues

#5
stdlib-js/stdlib#200
stdlib-js/stdlib#199
stdlib-js/stdlib#201

Checklist

  • I have read and understood the Code of Conduct.
  • I have read and understood the application materials found in this repository.
  • I understand that plagiarism will not be tolerated, and I have authored this application in my own words.
  • I have read and understood the patch requirement which is necessary for my application to be considered for acceptance.
  • I have read and understood the stdlib showcase requirement which is necessary for my application to be considered for acceptance.
  • The issue name begins with [RFC]: and succinctly describes your proposal.
  • I understand that, in order to apply to be a GSoC contributor, I must submit my final application to https://summerofcode.withgoogle.com/ before the submission deadline.
@abdelrahman04 abdelrahman04 added 2025 2025 GSoC proposal. rfc Project proposal. labels Mar 24, 2025
@abdelrahman04
Copy link
Author

@kgryte
Hello Athan,
I know my tinymt32 pr is not yet merged but what do you think on the suggested PRNGs?
And is there any change needed here?
Thanks

@kgryte
Copy link
Member

kgryte commented Mar 31, 2025

@abdelrahman04 Thank you for opening this RFC. For TinyMT64, how are you planning on supporting 64-bit integer arithmetic? What will be your fallback for 64-bit arithmetic emulation? And, given that we are more inclined to return integers up to 2^53, how will you adjust the algorithm accordingly?

Am I correct in assuming that you are planning on both JS and C implementations of the proposed PRNGs?

@abdelrahman04
Copy link
Author

@kgryte

how are you planning on supporting 64-bit integer arithmetic? What will be your fallback for 64-bit arithmetic emulation?

I had two ideas in mind, either add support for int64 in @stdlib/number which would be done way before the gsoc period, or implement the 64-bit arithmetic using 2 int32 and simulating the operations which isn't hard at all but I prefer the first option as it will readily give us the ability to implement other PRNGs needing 64 bits. and my fallback would be C's long long int implementation which would be a good fallback.

And, given that we are more inclined to return integers up to 2^53, how will you adjust the algorithm accordingly?

Well the tinymt64 naturally returns integeres up to 2^64, for the compression we could just discard the last 11 bits (this would be the same way you implemented the nextFloat in mt19937 where you just discard some bits at the end). and I am open if you have other ways in mind.

Am I correct in assuming that you are planning on both JS and C implementations of the proposed PRNGs?

Yes I will be adding JS and C implementations along with the benchmarks, examples, tests and src for all.

Lastly, should I submit the gsoc proposal right now and then we could have our own edits for the further improvements here?

Thanks

@kgryte kgryte added needs feedback received feedback A proposal which has received feedback. and removed needs feedback labels Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2025 2025 GSoC proposal. received feedback A proposal which has received feedback. rfc Project proposal.
Projects
None yet
Development

No branches or pull requests

2 participants