Skip to content

Instantly share code, notes, and snippets.

@xpepermint
Last active May 2, 2022 09:25
Show Gist options
  • Select an option

  • Save xpepermint/f9a0ab323c48de6440eb6b79ffd8456d to your computer and use it in GitHub Desktop.

Select an option

Save xpepermint/f9a0ab323c48de6440eb6b79ffd8456d to your computer and use it in GitHub Desktop.

Revisions

  1. xpepermint revised this gist May 2, 2022. 3 changed files with 9 additions and 0 deletions.
    File renamed without changes.
    9 changes: 9 additions & 0 deletions getrandom-crate.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    fn main() {
    println!("{:?}", get_random_buf());
    }

    fn get_random_buf() -> Result<[u8; 32], getrandom::Error> {
    let mut buf = [0u8; 32];
    getrandom::getrandom(&mut buf)?;
    Ok(buf)
    }
    File renamed without changes.
  2. xpepermint revised this gist May 2, 2022. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions from linux
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    use std::fs::File;
    use std::io::Read;

    fn main() {
    let mut f = File::open("/dev/urandom").unwrap(); // from Linux
    let mut buf = [0u8; 16];
    f.read_exact(&mut buf).unwrap();

    println!("{:?}", buf);
    }
  3. xpepermint created this gist May 2, 2022.
    11 changes: 11 additions & 0 deletions no dependency
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    fn main() {
    unsafe {
    srand();
    println!("{}", rand());
    }
    }

    extern "C" {
    fn srand() -> u32;
    fn rand() -> u32;
    }