Skip to content

Instantly share code, notes, and snippets.

@huhn511
Created May 29, 2020 23:22
Show Gist options
  • Save huhn511/8fc8a59b02a9dfd236d681447c9b2d71 to your computer and use it in GitHub Desktop.
Save huhn511/8fc8a59b02a9dfd236d681447c9b2d71 to your computer and use it in GitHub Desktop.
Create a random seed with rust
//!
//! To Generate a new Random Seed
//!
extern crate rand;
use rand::Rng;
///
/// Generates a new random String of 81 Chars of A..Z and 9
///
pub fn new() -> String {
const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ9";
const SEED_LEN: usize = 81;
let mut rng = rand::thread_rng();
let seed: String = (0..SEED_LEN)
.map(|_| {
let idx = rng.gen_range(0, CHARSET.len());
CHARSET[idx] as char
})
.collect();
seed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment