1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
mod equation;

pub use equation::{TwoFactor, SimpleTwoFactor, Equation, basic};


pub fn generate_two_factor(amount: usize, config: &Config) -> Vec<TwoFactor> {
	let mut equation_list = Vec::new();

	for _n in 0..amount {
		let equation = TwoFactor::new(&config.random_buffer());

		equation_list.push(equation);
	}

	equation_list
}




pub enum DifficultyMode {
	Easy,
	Normal,
	Hard,
	Lunatic,
}

pub struct Config {
	difficulty: DifficultyMode,
	random_buffer: [i32; 100],
}

impl Config {
	pub fn new(difficulty: DifficultyMode) -> Config {
		let range = number::set_range(&difficulty);
		
		Config {
			difficulty,
			random_buffer: number::generate_buffer(range),
		}
	}
	
	pub fn random_buffer(&self) -> &[i32; 100] {
		&self.random_buffer
	}
	
	pub fn difficulty(&self) -> &DifficultyMode {
		&self.difficulty
	}
}

mod number {
	use super::DifficultyMode;
	use random_number as rn;

	pub fn change_float_part(x: f64, decimal_count: usize) -> f64 {
		let power = match decimal_count {
			0 => 1.0,
			1 => 10.0,
			2 => 100.0,
			3 => 1000.0,
			4 => 10000.0,
			5 => 100000.0,
			_ => 100000.0,
		};

	
		let expanded = x * power; //145.7484
		let rounded = expanded.floor();
		let x_truncated = rounded / 100.0;

		x_truncated
	}

	pub fn generate_buffer(range_max_inclusive: i32) -> [i32; 100] {
		let mut random_buffer = [0; 100];
		rn::random_fill_ranged(&mut random_buffer, 0..=range_max_inclusive);
	
		random_buffer
	}
	
	
	pub fn set_range(difficulty: &DifficultyMode) -> i32 {
		match difficulty {
			DifficultyMode::Easy => 10,
			DifficultyMode::Normal => 25,
			DifficultyMode::Hard => 50,
			DifficultyMode::Lunatic => 100,
		}
	}
}