smol-rs / fastrand

A simple and fast random number generator
Apache License 2.0
386 stars 33 forks source link

Alternative Hash (ex : highway, xxh3) #69

Open chris-ha458 opened 1 year ago

chris-ha458 commented 1 year ago

wyrng has been shown to have some flaws within the randomness (from official repo )

Both of them are not 64 bit collision resistant, but is about 62 bits (flyingmutant/Cyan4973/vigna) When test on longer dataset (32TB, 23 days), wyrand will fail practrand (vigna)

Would there be interest in implementing an alternative hash?

If there is interest, I think I might take a try in implementing it. I think possible candidates would be highwayhash or xxh3 The former has a bit stronger preliminary (but not full) cryptanalysis. But both pass smhasher without problems without known hash issues.

Both are known to be fast. I do want to add that all algorithms, including wyhash, has strong and weak points regarding speed depending on input length, output length, specific implementation (if SIMD which ISA?). So I think it would not be fair to judge speed without seeing the actual implementation here.

If there is interest I might proceed as follows. I shall assume that there is a desire here to keep it simple and not add another dependency

  1. abstract current implementation within the codebase and isolate it
  2. implement an alternate hash and then provide a way to select it, or maintain a branch
  3. provide benchmarks to compare the two.
notgull commented 1 year ago

I will accept a PR to change the RNG algorithm if the benchmarks show that it is faster. However I am against having more than one supported RNG algorithm, as that is out of scope for this crate and would be more in scope for something like rand.