Implemented multi-threaded CPU-miner.

This commit is contained in:
Revertron
2021-01-14 18:34:43 +01:00
parent 01f37cc238
commit 4703ae6f49
9 changed files with 299 additions and 119 deletions
+14
View File
@@ -1,4 +1,5 @@
use std::num;
use rand::Rng;
/// Convert bytes array to HEX format
pub fn to_hex(buf: &[u8]) -> String {
@@ -30,4 +31,17 @@ pub fn same_hash(left: &[u8], right: &[u8]) -> bool {
}
}
true
}
/// Generates random string of given length
pub fn random_string(length: usize) -> String {
let chars: Vec<char> = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?".chars().collect();
let mut rng = rand::thread_rng();
let mut result = String::with_capacity(length);
for x in 0..length {
let position: usize = rng.gen::<usize>() % chars.len();
let c: char = *chars.get(position).unwrap();
result.push(c);
}
result
}