unity-random 1.0.0

A reimplementation of Unity's pseudo-random number generator.
Documentation
  • Coverage
  • 50%
    4 out of 8 items documented0 out of 0 items with examples
  • Size
  • Source code size: 36.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 691.11 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • minavoii/unity-random
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • minavoii

Unity-Random

A full reimplementation of Unity's PRNG in Rust, which is based on the Xorshift128 algorithm.

Results should be near 1-to-1 with Unity, with the exception of color() which may produce slightly inaccurate results due to an issue with .NET versions before 5.x.

Unlike Unity, it does not offer a static class.

Note: you should not use this if you expect a cryptographically secure PRNG. If you just want to generate random numbers, you should be looking into the Rand crate.

This project is not affiliated with Unity Technologies.

Usage

use unity_random::Random;
let mut random = Random::new();
random.init_state(220824); // set the PRNG seed

let integer = random.range_int(0, 100);
let float = random.range_float(0., 1.);
let rotation = random.rotation_uniform();

You can also save/load the current state:

use unity_random::Random;
let mut random = Random::new();
random.init_state(220824);

// You can save the current state...
let saved_state = random.state;

// then generate random numbers...
let i1 = random.range_int(0, 100);

// and load the state again...
random.state = saved_state;

// ... to generate the same sequence
let i2 = random.range_int(0, 100);
assert_eq!(i1, i2);

Feature flags

  • serde: Enables serialization and deserialization of the PRNG's State.