Created
May 29, 2020 23:22
-
-
Save huhn511/8fc8a59b02a9dfd236d681447c9b2d71 to your computer and use it in GitHub Desktop.
Create a random seed with rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! | |
//! 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