1
0

Add noise to rng

This commit is contained in:
Mark 2025-03-02 10:38:06 -08:00
parent 9fc8654e7b
commit 88ed908faa
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
2 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,4 @@
- quick drop
- better rng
- fix asm loader
- document everything
- prettier pictures

View File

@ -6,7 +6,7 @@
use core::arch::asm;
use lazy_static::lazy_static;
use rand::{rngs::SmallRng, SeedableRng};
use rand::{rngs::SmallRng, Rng, SeedableRng};
use spin::Mutex;
use drivers::{pic::PICDriver, vga::Vga13h};
@ -89,6 +89,16 @@ enum InputKey {
}
extern "x86-interrupt" fn keyboard_handler(_stack_frame: InterruptStackFrame) {
{
// Re-seed our rng using user input.
// This is a simple hack that makes our
// "random" tile selector less deterministic.
let mut rng = RNG.lock();
let past: u64 = rng.random();
let tcr = u64::from(*TICK_COUNTER.lock());
*rng = SmallRng::seed_from_u64(past + tcr);
}
'key_block: {
let scancode = unsafe { inb(0x60) };
let key = match scancode {