2023-09-29 19:35:01 +05:30
|
|
|
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2023-09-05 19:21:30 +05:30
|
|
|
/// Get random string of specific length
|
|
|
|
pub(crate) fn get_random(len: usize) -> String {
|
|
|
|
use rand::{distributions::Alphanumeric, rngs::ThreadRng, thread_rng, Rng};
|
|
|
|
use std::iter;
|
|
|
|
|
|
|
|
let mut rng: ThreadRng = thread_rng();
|
|
|
|
|
|
|
|
iter::repeat(())
|
|
|
|
.map(|()| rng.sample(Alphanumeric))
|
|
|
|
.map(char::from)
|
|
|
|
.take(len)
|
|
|
|
.collect::<String>()
|
|
|
|
}
|