# RANDU [![Version](https://img.shields.io/crates/v/randu.svg)](https://crates.io/crates/randu) [![License](https://img.shields.io/crates/l/randu)](https://unlicense.org) [![MSRV](https://img.shields.io/crates/msrv/randu?logo=rust&label=MSRV&labelColor=orange)](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html) [![no-std ready](https://img.shields.io/badge/no--std-compatible-limegreen?logo=rust&labelColor=blanchedalmond&logoColor=black)](https://docs.rust-embedded.org/book/intro/no-std.html) [![Safe Rust](https://img.shields.io/badge/Rust-safe-brightgreen.svg)](https://doc.rust-lang.org/nomicon/meet-safe-and-unsafe.html) [![dependency status](https://deps.rs/repo/gitlab/hsn10/randu/status.svg)](https://deps.rs/repo/gitlab/hsn10/randu) [![Documentation](https://docs.rs/randu/badge.svg)](https://docs.rs/randu) [![Downloads](https://img.shields.io/crates/d/randu)](https://crates.io/crates/randu/versions) [![](https://tokei.rs/b1/gitlab/hsn10/randu?category=code)](https://github.com/XAMPPRocky/tokei) RANDU is Pseudorandom multiplicative [congruential generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) (MCG). This generator was first introduced in the early 1960s; its use soon became widespread during 1960's and 1970's. Its part of the IBM Scientific Subroutine Library for IBM System/360 computers. RANDU uses MCG coeficients _multiplier a_ = 65539 ( 2^16 + 3 ) and _modulus m_ = 2^31 and _constant c_ = 0. It can be implemented very quickly on 32-bit hardware in just 2 operations: wrapping multiplication by _a_ and bit masking of result using AND _0x7fffffff_. Generated values are positive 31 bit integers. Generator period is 2^29. Lower bits have low randomness and should not be used separately. Problem with lower bits randomness and not achieving full period is common for all congruential generators with power of 2 modulus. RANDU fails the spectral test for dimensions greater than 2. RANDU produces very [strong banding](https://www.juliabloggers.com/dissecting-randu/) when used in 3 dimensions. All points in 3d space fall in 15 two-dimensional planes. This effect can be used in GPU programming for visual effects and take advantage of compute simplicity. ### References https://en.wikipedia.org/wiki/RANDU https://oeis.org/A096555 https://en.wikipedia.org/wiki/Linear_congruential_generator ## Spectral test | 2d | 3d | 4d | 5d | 6d | 7d | 8d | | --- | ---- | ----- | ---- | ---- | ---- | ---- | |0.93 | 0.012 | 0.059 | 0.16 | 0.29 | 0.45 | 0.62 | Values 0.75 and higher are commonly considered as passing of the spectral test. While this generator failing higher dimensions it is a _very strong_ in generating 2d data. ## License This is free and unencumbered software released into the public domain. This code can be used under terms of [CC0](https://creativecommons.org/publicdomain/zero/1.0/) or the [Unlicense](https://unlicense.org). ![Unlicense logo](https://unlicense.org/pd-icon.png)