Skip to content

Create our own Random class using the xoshiro256 algorithm#396

Open
initsu wants to merge 11 commits intoEllendar:5.1from
initsu:new-rng
Open

Create our own Random class using the xoshiro256 algorithm#396
initsu wants to merge 11 commits intoEllendar:5.1from
initsu:new-rng

Conversation

@initsu
Copy link
Copy Markdown
Collaborator

@initsu initsu commented Mar 17, 2026

I did not find a library that satisfied all requirements, so I just made a variant of existing open source (MIT or Public Domain) code.

  • This same algorithm can be chosen by .NET internally (and is Public Domain), but there is no guarantee that this is the case. By having a specific implementation, we can guarantee deterministic output.
  • This gives access to the state of the Random object at any point via GetState and SetState methods that use Base64 strings. This should allow us to capture the RNG state if an error occurs and reproduce it as needed.
  • This Random class exists in the RandomizerCore package and will take precedence when working inside this package. It is not a subclass of the System.Random class, so trying to use the wrong class somewhere will just not compile. It has no constructor without a seed. When we don't need to specify a seed, we can still use System.Random (as that implies we don't care about deterministic output).

Implements #395

@Ellendar Ellendar added this to the 5.2 milestone Mar 17, 2026
@Ellendar
Copy link
Copy Markdown
Owner

Not going to merge this for 5.1 . Probably just adding it wont cause issues but actually using it is not something I want to introduce when i'm trying to finish up and be ready to ship 5.1. Feel free to start up a branch for 5.2 and we can merge it there.

Ellendar and others added 11 commits April 3, 2026 16:48
- This same algorithm can be chosen by .NET internally (and is Public Domain),
  but there is no guarantee that this is the case. By having a specific
  implementation, we can guarantee deterministic output.
- This gives access to the state of the Random object at any point via
  GetState and SetState methods that use Base64 strings. This should allow
  us to capture the RNG state if an error occurs and reproduce it as needed.
- This Random class exists in the RandomizerCore package and will take
  precedence when working inside this package. It is not a subclass of the
  System.Random class, so trying to use the wrong class somewhere will just
  not compile. It has no constructor without a seed. When we don't need to
  specify a seed, we can still use System.Random (as that implies we don't
  care about deterministic output).

Implements Ellendar#395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants