aboutsummaryrefslogtreecommitdiff
path: root/src/garage/tests/common/util.rs
blob: 49c728799ea461632be3f6b3bf32a7f0329ca8b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
pub fn random_id(len: usize) -> String {
	use rand::distributions::Slice;
	use rand::Rng;

	static ALPHABET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789.";

	let rng = rand::thread_rng();
	rng.sample_iter(Slice::new(ALPHABET).unwrap())
		.map(|b| char::from(*b))
		.filter(|c| c.is_ascii_lowercase() || c.is_ascii_digit())
		.take(len)
		.collect()
}