* fixed _unix_random bug * add custom instruction "random" * update to spec 1.12 * more cli options
14 lines
404 B
Rust
14 lines
404 B
Rust
use std::fs::File;
|
|
use std::io::Read;
|
|
use crate::RunError;
|
|
|
|
#[cfg(target_family = "unix")]
|
|
pub fn _unix_random(memory: &mut Vec<u16>) {
|
|
let mut rng = File::open("/dev/urandom").unwrap();
|
|
|
|
let mut buffer = [0u8; 2];
|
|
rng.read_exact(&mut buffer).unwrap();
|
|
|
|
let data = &memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
|
memory.push((u16::from_ne_bytes(buffer)) % (*data - 1));
|
|
} |