Skip to content

Standardize deterministic RNG in examples #12613

@BD103

Description

@BD103

If we are emphasising that the seeded rng is being used for deterministic purposes, then we kinda shouldn't be using StdRng in the first place. StdRng is documented as being deterministic in output, but not portable, so there is no assurance that the output will be the same on different platforms or different versions of rand. And if we are testing across different platforms, we'd then expect the output to match across all platforms. For further reference from the rand documentation, their documented expectations for portability/determinism.

Given rand minor versions might in the future change the underlying algorithm for StdRng, end users might find their tests breaking if they used StdRng in their tests after basing them on our examples. Better to instead encourage using the algorithm crates directly if they want to have that extra assurance in determinism. Currently, rand_chacha is what is the underlying algorithm for StdRng, specifically ChaCha12Rng. For game dev purposes, ChaCha8Rng would be a better fit to provide higher throughput at the expense of some entropy quality (though it will still be far better than what is probably required).

Originally posted by @Bluefinger in #12593 (comment)

I think a good PR would be to replace all usage of StdRng with ChaCha8Rng, as suggested by @Bluefinger. There are also a few examples that use hashing instead of a proper RNG function that could benefit from switching too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-ExamplesAn addition or correction to our examplesD-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions