Posts

Showing posts from June, 2020

Generating UUID4 from custom random number generator (RNG) using rust

First you need to generate random seed: It can be from any RNG generator, for example in near protocol sdk,  https://docs.rs/near-sdk/0.11.0/near_sdk/env/fn.random_seed.html pub fn random_seed() -> Vec<u8> use rand::Rng; fn main () { let mut rng = rand::thread_rng(); let mut randvec: Vec < u8 > = Vec ::new(); let mut counter = 0 ; let result = loop { counter += 1 ; let n1: u8 = rng.gen(); randvec.push(n1); if counter == 32 { break randvec; } }; println! ( "{:?}" , result); } Its generate vector, but you need an array to feed into from_seed function. This is the complete code. use rand::{rngs::StdRng, RngCore, SeedableRng, Rng}; use uuid::{Builder, Variant, Version}; fn main () { let mut rng = rand::thread_rng(); let mut randvec: Vec < u8 > = Vec ::new(); let mut counter = 0 ; let result_vec = loop { counter ...