Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more non-cryptographic prngs to the crate #1109

Closed
DKenefake opened this issue Apr 1, 2021 · 7 comments
Closed

Adding more non-cryptographic prngs to the crate #1109

DKenefake opened this issue Apr 1, 2021 · 7 comments

Comments

@DKenefake
Copy link

DKenefake commented Apr 1, 2021

Background

What is your motivation?
I want there to be greater availability of standard prngs available in the Rust ecosystem.

What type of application is this? (E.g., cryptography, game, numerical simulation)
Monte-Carlo simulations and general use.

Feature request

The addition of additional non-cryptographic prngs to the crate. I have a small c++ prng lib that implements several generators (with validated implementations via big crush) that I think would be simple to port to this crate. Please let me know if there is an appetite for this development, as I could do (the majority) of the porting.

The prngs I am thinking are the following.

General Xorshift Family

  • Xorshift32
  • Xorshift64
  • Xorshift128
  • Xorshift128+
  • Xoroshiro**256

Middle Square Algos

  • original middle square
  • modified middle square from this paper

Other Generators

  • splitmix32 from this paper
  • jsf from this website
  • LCG with Knuth's parameters
@vks
Copy link
Collaborator

vks commented Apr 1, 2021

What is the motivation for having so many non-crypto RNGs? If you want, you can already publish a crate with additional RNGs.

Xoshiro256** is available in rand_xoshiro.

@DKenefake
Copy link
Author

Different prngs have differing statistical behaviors depending on the Monte-Carlo experiment; different prngs might become more favorable than others (for physical simulation, etc.). My thought was that this crate is the central random number crate in the Rust ecosystem. I thought it would make sense to have these algorithmic implementations in this crate. Unfortunately, I do not have the mental bandwidth to maintain my own crate (grad school).

Ahh, I didn't know that Xoshiro256** was already available in Rust.

@TheIronBorn
Copy link
Contributor

TheIronBorn commented Apr 2, 2021

Isn't it Xoshiro256++?

Oh huh.

/// A xoshiro256** random number generator.
vs
pub struct Xoshiro256PlusPlus {
and
let result_plusplus = self.s[0]
.wrapping_add(self.s[3])
.rotate_left(23)
.wrapping_add(self.s[0]);

Xoshiro128PlusPlus seems fine.

@dhardy
Copy link
Member

dhardy commented Apr 2, 2021

@TheIronBorn Xoshiro has both ++ and ** variants: see https://prng.di.unimi.it/#intro

@DKenefake we do have several non-crypto PRNGs, especially Xoshiro variants. Did you see the https://github.com/rust-random/rngs repo? You might also try some crypto RNGs, especially ChaCha8 which is quite fast.

Certainly there are several well-known PRNGs we don't have; you may open up issues/PRs about implementing them on the rngs repo if you like, but don't expect someone else to do all the work for you. (Though once accepted into the rngs repo we can take over maintenance — with help from the community.)

@TheIronBorn
Copy link
Contributor

@dhardy yes but that xoshiro256** documentation is for the Xoshiro256PlusPlus prng. I suppose I should just have made an issue

@DKenefake
Copy link
Author

Ahh, I didn't see that! For most of my use cases, cryptographic prngs are not fast enough.

I was only asked if there was an appetite for a port and not others to do the port. I didn't want to go thru the trouble of porting and then it not be accepted. What I was asking here was which of these prngs would be wanted.

@dhardy
Copy link
Member

dhardy commented Apr 3, 2021

Sorry, I seem to have developed a habit for skim-reading posts! If you're interested, we did some of our own investigations into small PRNGs:

So adding JSF and SFC might be nice.

Note that we also have a couple of PCG generators implemented: https://docs.rs/rand_pcg/0.3.0/rand_pcg/

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

No branches or pull requests

4 participants