mirror of https://github.com/sgoudham/uwuifyy.git
Speewd *UwU*
parent
6be7aea531
commit
29292bd1c9
File diff suppressed because it is too large
Load Diff
@ -1,29 +1,26 @@
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
|
||||
pub struct UwUProgressBar {
|
||||
downloaded_bytes: u64,
|
||||
progress_bar: ProgressBar,
|
||||
}
|
||||
#[repr(transparent)]
|
||||
pub struct UwUProgressBar(ProgressBar);
|
||||
|
||||
impl UwUProgressBar {
|
||||
#[inline]
|
||||
pub fn new(file_total_bytes: u64) -> UwUProgressBar {
|
||||
let progress_bar = ProgressBar::new(file_total_bytes);
|
||||
progress_bar.set_style(ProgressStyle::default_bar()
|
||||
.template("{spinner:.green} [{elapsed_precise}] [{bar:60.cyan/blue}] {bytes}/{total_bytes} ({eta}) {msg}")
|
||||
.progress_chars("#>-"));
|
||||
|
||||
UwUProgressBar {
|
||||
downloaded_bytes: 0,
|
||||
progress_bar,
|
||||
}
|
||||
UwUProgressBar(progress_bar)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn update_progess(&mut self, bytes_read_in: usize) {
|
||||
self.downloaded_bytes += bytes_read_in as u64;
|
||||
self.progress_bar.set_position(self.downloaded_bytes);
|
||||
self.0.inc(bytes_read_in as u64);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finish(&self, message: &'static str) {
|
||||
self.progress_bar.finish_with_message(message);
|
||||
self.0.finish_with_message(message);
|
||||
}
|
||||
}
|
@ -1,35 +1,41 @@
|
||||
use rand::{Rng, rngs::ThreadRng, thread_rng};
|
||||
use rand_pcg::Pcg32;
|
||||
use rand_seeder::Seeder;
|
||||
use std::hash::Hasher;
|
||||
|
||||
use rand::{
|
||||
distributions::uniform::{SampleRange, SampleUniform},
|
||||
Rng, RngCore, SeedableRng,
|
||||
};
|
||||
use rand_xoshiro::{Xoshiro256Plus, Xoshiro256PlusPlus};
|
||||
|
||||
pub struct UwUSeeder {
|
||||
seeder: Pcg32,
|
||||
rng: ThreadRng,
|
||||
random: bool,
|
||||
floating: Xoshiro256Plus,
|
||||
int: Xoshiro256PlusPlus,
|
||||
}
|
||||
|
||||
impl UwUSeeder {
|
||||
#[inline]
|
||||
pub fn new(word: &str, random: bool) -> UwUSeeder {
|
||||
let entropy = match random {
|
||||
true => rand::rngs::OsRng.next_u64(),
|
||||
false => {
|
||||
let mut hasher = ahash::AHasher::default();
|
||||
hasher.write(word.as_bytes());
|
||||
hasher.finish()
|
||||
}
|
||||
};
|
||||
|
||||
UwUSeeder {
|
||||
seeder: Seeder::from(word).make_rng(),
|
||||
rng: thread_rng(),
|
||||
random,
|
||||
floating: Xoshiro256Plus::seed_from_u64(entropy),
|
||||
int: Xoshiro256PlusPlus::seed_from_u64(entropy),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn random(&mut self) -> f32 {
|
||||
if self.random {
|
||||
self.rng.gen_range(0.0..1.0)
|
||||
} else {
|
||||
self.seeder.gen_range(0.0..1.0)
|
||||
}
|
||||
#[inline]
|
||||
pub fn random(&mut self) -> f64 {
|
||||
f64::from_ne_bytes(self.floating.next_u64().to_ne_bytes())
|
||||
}
|
||||
|
||||
pub fn random_int(&mut self, min: i32, max: i32) -> usize {
|
||||
if self.random {
|
||||
self.rng.gen_range(min..max) as usize
|
||||
} else {
|
||||
self.seeder.gen_range(min..max) as usize
|
||||
}
|
||||
#[inline]
|
||||
pub fn random_int<T: SampleUniform, R: SampleRange<T>>(&mut self, range: R) -> T {
|
||||
self.int.gen_range(range)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue