Expand description
§Bevy PRNG
§What is Bevy PRNG?
bevy_prng
is a crate that provides newtyped versions of various rand_*
PRNG algorithm crates to make them suitable for integration within bevy
for reflection purposes. It enables these types to have stable TypePath
s and otherwise implement various required traits. This crate can be used as standalone to provide access to various PRNG algorithms of one’s choice, to then use to write components/resources for one’s game in bevy
, but primarily, it’s purpose to support and be a counterpart to bevy_rand
(which provides the generic wrapper component/resource that bevy_prng
types can plug in to).
This crate is no_std
compatible.
§Using Bevy PRNG
By default, bevy_prng
won’t export anything unless the feature/algorithm you require is explicitly defined. In order to gain access to a newtyped PRNG struct, you’ll have activate one of the following features:
bevy_reflect
- Enables reflection support for allbevy_prng
types.std
- This enables somestd
specific functionality in some PRNGs, particularly inrand_chacha
. Only forstd
environments.rand_chacha
- This enables the exporting of newtypedChaCha*Rng
structs, for those that want/need to use a CSPRNG level source.rand_pcg
- This enables the exporting of newtypedPcg*
structs fromrand_pcg
.rand_xoshiro
- This enables the exporting of newtypedXoshiro*
structs fromrand_xoshiro
. It also exports a remote-reflected version ofSeed512
so to allow setting upXoshiro512StarStar
and so forth.wyrand
- This enables the exporting of newtypedWyRand
fromwyrand
, the same algorithm in use withinfastrand
/turborand
.compat
- This enables the oldRngCore
trait implementations on the RNGs, providing additional compatibility with other crates that haven’t yet upgraded to the latestrand_core
/rand
versions.
In addition to these feature flags to enable various supported algorithms, there’s also serialize
flag to provide serde
support for Serialize
/Deserialize
, which is enabled by default.
All types are provided at the top-level of the module:
use bevy_prng::*;
§Supported PRNG Algorithms/Crates
All the below crates implement the necessary traits to be compatible with bevy_prng
. Additional PRNG crates can be added via PR’s to this crate/repo, provided the PRNGs implement Debug
, Clone
, PartialEq
and have optional Serialize
/Deserialize
serde
traits implemented and put behind appropriate feature flags.
§Cryptographically Secure PRNGs
§Non-Cryptographically Secure PRNGS
§Supported Versions & MSRV
bevy_prng
uses the same MSRV as bevy
.
bevy | bevy_prng |
---|---|
v0.16 | v0.10 - v0.11 |
v0.15 | v0.8 - v0.9 |
v0.14 | v0.7 - v0.8 |
v0.13 | v0.5 - v0.6 |
v0.12 | v0.2 |
v0.11 | v0.1 |
The versions of rand_core
/rand
that bevy_prng
is compatible with is as follows:
bevy_prng | rand_core | rand | getrandom | compat feature |
---|---|---|---|---|
v0.10 -> v0.11 | v0.9 | v0.9 | v0.3 | ✅ (supports rand_core v0.6) |
v0.1 -> v0.9 | v0.6 | v0.8 | v0.2 | ❌ |
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Structs§
- ChaCha8
Rng rand_chacha
- A newtyped
rand_chacha::ChaCha8Rng
RNG - ChaCha12
Rng rand_chacha
- A newtyped
rand_chacha::ChaCha12Rng
RNG - ChaCha20
Rng rand_chacha
- A newtyped
rand_chacha::ChaCha20Rng
RNG - Pcg32
rand_pcg
- A newtyped
rand_pcg::Pcg32
RNG - Pcg64
rand_pcg
- A newtyped
rand_pcg::Pcg64
RNG - Pcg64
Mcg rand_pcg
- A newtyped
rand_pcg::Pcg64Mcg
RNG - WyRand
- A newtyped
wyrand::WyRand
RNG - Xoroshiro64
Star rand_xoshiro
- A newtyped
rand_xoshiro::Xoroshiro64Star
RNG - Xoroshiro64
Star Star rand_xoshiro
- A newtyped
rand_xoshiro::Xoroshiro64StarStar
RNG - Xoroshiro128
Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro128Plus
RNG - Xoroshiro128
Plus Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro256PlusPlus
RNG - Xoroshiro128
Star Star rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro128StarStar
RNG - Xoshiro128
Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro128Plus
RNG - Xoshiro128
Plus Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro256PlusPlus
RNG - Xoshiro128
Star Star rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro128StarStar
RNG - Xoshiro256
Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro256Plus
RNG - Xoshiro256
Plus Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro256PlusPlus
RNG - Xoshiro256
Star Star rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro256StarStar
RNG - Xoshiro512
Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro512Plus
RNG - Xoshiro512
Plus Plus rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro512PlusPlus
RNG - Xoshiro512
Star Star rand_xoshiro
- A newtyped
rand_xoshiro::Xoshiro512StarStar
RNG
Traits§
- Entropy
Seed - Marker trait for a suitable seed for
EntropySource
. This is an auto trait which will apply to all suitable types that meet the trait criteria. - Entropy
Source - A marker trait to define the required trait bounds for a seedable PRNG to
integrate into
Entropy
orGlobalEntropy
. This is a sealed trait. - RngReflectable
- Trait for handling contraints for valid implementations of
EntropySource
depending on whether reflection support is enabled or not - Typed
Seed - Trait for handling
SeedableRng
requirements, imposing constraints depending on whether reflection support is enabled or not