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};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
|
|
||||||
pub struct UwUProgressBar {
|
#[repr(transparent)]
|
||||||
downloaded_bytes: u64,
|
pub struct UwUProgressBar(ProgressBar);
|
||||||
progress_bar: ProgressBar,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UwUProgressBar {
|
impl UwUProgressBar {
|
||||||
|
#[inline]
|
||||||
pub fn new(file_total_bytes: u64) -> UwUProgressBar {
|
pub fn new(file_total_bytes: u64) -> UwUProgressBar {
|
||||||
let progress_bar = ProgressBar::new(file_total_bytes);
|
let progress_bar = ProgressBar::new(file_total_bytes);
|
||||||
progress_bar.set_style(ProgressStyle::default_bar()
|
progress_bar.set_style(ProgressStyle::default_bar()
|
||||||
.template("{spinner:.green} [{elapsed_precise}] [{bar:60.cyan/blue}] {bytes}/{total_bytes} ({eta}) {msg}")
|
.template("{spinner:.green} [{elapsed_precise}] [{bar:60.cyan/blue}] {bytes}/{total_bytes} ({eta}) {msg}")
|
||||||
.progress_chars("#>-"));
|
.progress_chars("#>-"));
|
||||||
|
|
||||||
UwUProgressBar {
|
UwUProgressBar(progress_bar)
|
||||||
downloaded_bytes: 0,
|
|
||||||
progress_bar,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn update_progess(&mut self, bytes_read_in: usize) {
|
pub fn update_progess(&mut self, bytes_read_in: usize) {
|
||||||
self.downloaded_bytes += bytes_read_in as u64;
|
self.0.inc(bytes_read_in as u64);
|
||||||
self.progress_bar.set_position(self.downloaded_bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn finish(&self, message: &'static str) {
|
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 std::hash::Hasher;
|
||||||
use rand_pcg::Pcg32;
|
|
||||||
use rand_seeder::Seeder;
|
use rand::{
|
||||||
|
distributions::uniform::{SampleRange, SampleUniform},
|
||||||
|
Rng, RngCore, SeedableRng,
|
||||||
|
};
|
||||||
|
use rand_xoshiro::{Xoshiro256Plus, Xoshiro256PlusPlus};
|
||||||
|
|
||||||
pub struct UwUSeeder {
|
pub struct UwUSeeder {
|
||||||
seeder: Pcg32,
|
floating: Xoshiro256Plus,
|
||||||
rng: ThreadRng,
|
int: Xoshiro256PlusPlus,
|
||||||
random: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UwUSeeder {
|
impl UwUSeeder {
|
||||||
|
#[inline]
|
||||||
pub fn new(word: &str, random: bool) -> UwUSeeder {
|
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 {
|
UwUSeeder {
|
||||||
seeder: Seeder::from(word).make_rng(),
|
floating: Xoshiro256Plus::seed_from_u64(entropy),
|
||||||
rng: thread_rng(),
|
int: Xoshiro256PlusPlus::seed_from_u64(entropy),
|
||||||
random,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random(&mut self) -> f32 {
|
#[inline]
|
||||||
if self.random {
|
pub fn random(&mut self) -> f64 {
|
||||||
self.rng.gen_range(0.0..1.0)
|
f64::from_ne_bytes(self.floating.next_u64().to_ne_bytes())
|
||||||
} else {
|
|
||||||
self.seeder.gen_range(0.0..1.0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random_int(&mut self, min: i32, max: i32) -> usize {
|
#[inline]
|
||||||
if self.random {
|
pub fn random_int<T: SampleUniform, R: SampleRange<T>>(&mut self, range: R) -> T {
|
||||||
self.rng.gen_range(min..max) as usize
|
self.int.gen_range(range)
|
||||||
} else {
|
|
||||||
self.seeder.gen_range(min..max) as usize
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue