package

github.com/ysbaddaden/random.cr

main / published Nov 7, 2025 / repository

PRNG collection for the Crystal language

Random

A collection of Pseudo Random Number Generators (PRNG) algorithms for the Crystal language. Each implementation implements the Random interface.

Continuation of the crystal-random shard.

Installation

Add the shard:

dependencies:
  random:
    github: ysbaddaden/random.cr

Usage

You may require random/all to include all algorithms, but it is recommended to specify the chosen algorithms such as random/xorshift128plus for example.

Algorithms

Sorted by increasing state.

PRNGwspeed (x86)speed (arm)StateSplittableCryptographyTestU01Comment
Random::XorShift3232-bit4.01ns3.24ns2$^{32}NoNoFailstoo many TESTU01 failures
Random::ISAAC (stdlib)32-bit8.02ns8.71ns2$^{64}NoYes-
Random::PCG32 (stdlib)32-bit4.41ns3.77ns2$^{64}NoNoBig Crush
Random::PCG6464-bit4.47ns7.20ns2$^{64}NoNo?
Random::SplitMix6464-bit3.77ns4.13ns2$^{64}NoNoBig Crushused to seed XoShiRo128 and XoShiRo256
Random::Splittable64-bit3.46ns3.91ns2$^{64}YesNoBig Crush
Random::XorShift6464-bit3.55ns2.52ns !2$^{64}NoNoFails
Random::XorShift64Plus32-bit4.47ns3.77ns2$^{64}NoNoSmall Crushfor Float32 numbers
Random::XorShift64Star64-bit3.51ns3.01ns2$^{64}NoNoFailsfor Float64 numbers
Random::XoRoShiRo64StarStar32-bit4.75ns4.10ns2$^{64}NoNoBig Crushall purpose generator
Random::WyRand64-bit3.15ns !5.18ns2$^{64}NoNoBig Crush
Random::Lehmer6464-bit3.15ns !5.53ns2$^{128}NoNoBig Crushsimplest
Random::Splittable12864-bit4.24ns4.70ns2$^{128}YesNoBig Crush
Random::XorShift12832-bit5.97ns4.89ns2$^{128}NoNoFails
Random::XorShift128Plus64-bit3.38ns2.91ns2$^{128}NoNo?for Float64 numbers
Random::XoShiRo128StarStar32-bit5.23ns4.15ns2$^{128}YesNoBig Crushall purpose generator
Random::XoShiRo128Plus32-bit5.04ns4.28ns2$^{128}YesNo?for Float32 numbers
Random::XoShiRo256PlusPlus64-bit4.07ns3.60ns2$^{256}YesNoBig Crushall purpose generator
Random::XoShiRo256StarStar64-bit3.97ns3.50ns2$^{256}YesNoBig Crushall purpose generator
Random::XoShiRo256Plus64-bit3.90ns3.76ns2$^{256}YesNo?for Float64 numbers
Random::XorShift1024Star64-bit3.77ns4.00ns2$^{1024}YesNoFailsfor massive parallel computations
Random::MT1993732-bit6.64ns5.13ns2$^{19937}NoNoFailsMersenne Twister (removed from stdlib)

The Plus and Star scrambles for the xorshift family (including xoshiro and xoroshiro) all fail BigCrush, but are still statistically correct enough to generate floating-point numbers (either Float32 or Float64) since their weakest bits are skipped.

The algorithms were benchmarked on an Intel Core i7-4712HQ (Haswell) and an Neoverse-N1 ARM server.

The TESTU01 results are aggregated from the following pages by Sebastiano Vigna and Daniel Lemire, as well as different papers.

TODO:

  • [ ] Random::ISAAC64
  • [ ] Random::ChaCha12
  • [ ] Random::ChaCha20

Maybe also:

  • [ ] Random::MWC128
  • [ ] Random::MWC256
  • [ ] Random::MWC512
  • [ ] Random::GMWC128
  • [ ] Random::GMWC256
  • [ ] Random::WELL512
  • [ ] Random::WELL1024
  • [ ] Random::WELL19937
  • [ ] Random::WELL44497
  • [ ] Random::XorWow
  • [ ] Random::XoRoShiRo64Star
  • [ ] Random::XoRoShiRo128Plus
  • [ ] Random::XoRoShiRo128PlusPlus
  • [ ] Random::XoRoShiRo128StarStar
  • [ ] Random::XoShiRo512Plus
  • [ ] Random::XoShiRo512PlusPlus
  • [ ] Random::XoShiRo512StarStar
  • [ ] Random::XoRoShiRo1024PlusPlus
  • [ ] Random::XoRoShiRo1024StarStar
  • [ ] Random::XoRoShiRo1024Star

License

Distributed under the Apache-2.0 license.

Contributors

  • Julien Portalier (@ysbaddaden)
  • crystal-lang The Crystal Lang Team - creator, maintainer

API

This version publishes no documented types.