Skip to content

Instantly share code, notes, and snippets.

@gre
Last active August 14, 2022 11:45
Show Gist options
  • Save gre/9e9ff87a0631bcf71a90e032d68ad6a7 to your computer and use it in GitHub Desktop.
Save gre/9e9ff87a0631bcf71a90e032d68ad6a7 to your computer and use it in GitHub Desktop.
// need libs: rand + bs58
use rand::rngs::StdRng;
fn rng_from_fxhash(hash: String) -> impl Rng {
let mut bs = [0; 32];
let max_chars = 43; // hack to not overflow the bs array
bs58::decode(
hash.chars().skip(2).take(max_chars).collect::<String>(),
)
.into(&mut bs)
.unwrap();
let rng = StdRng::from_seed(bs);
return rng;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment