Random number generator (device): Difference between revisions
Content added Content deleted
m (→{{header|D}}) |
|||
Line 786: | Line 786: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
<code>rand</code> used to be part of Rust standard library but it was extracted as a 'crate' (https://crates.io/crates/rand). <code>OsRng</code> uses the appropriate device for many platforms including Unix, Windows, BSD, and iOS (listed [https://docs.rs/rand/0.4/rand/os/struct.OsRng.html here]). Other methods like <code>RDRAND</code> can be found in other crates (https://crates.io/crates/rdrand). |
|||
<lang rust> |
<lang rust>extern crate rand; |
||
extern crate rand; |
|||
use rand::{ |
use rand::{OsRng, Rng}; |
||
fn main() { |
fn main() { |
||
// because `OsRng` opens files, it may fail |
|||
let mut rng = match OsRng::new() { |
let mut rng = match OsRng::new() { |
||
Ok(v) => v, |
Ok(v) => v, |
||
Line 799: | Line 799: | ||
}; |
}; |
||
let rand_num:u32 = rng. |
let rand_num: u32 = rng.gen(); |
||
println!("{}",rand_num); |
println!("{}", rand_num); |
||
⚫ | |||
} |
|||
⚫ | |||
=={{header|Sidef}}== |
=={{header|Sidef}}== |