Hello! This code needs a small update. Here's a working version which still uses rand = "0.8.5" in cargo.toml dependencies. Updated Code: use rand::Rng; fn main() { let random_number = rand::thread_rng().gen_range(1..11); println!("Random Number: {}", random_number); //random bool let random_bool = rand::thread_rng().gen_bool(1.0/2.0); println!("Random Boolean: {}", random_bool); }
For those curious, gen_weighted_bool() is no longer avaliable in the rand crate, you need to use gen_bool(), which takes a floating-point probability from 0.0 to 1.0
nice tutorials, just want to mention, that you don't need to write `extern crate rand;` since rust edition 2018
Hello! This code needs a small update. Here's a working version which still uses rand = "0.8.5" in cargo.toml dependencies.
Updated Code:
use rand::Rng;
fn main()
{
let random_number = rand::thread_rng().gen_range(1..11);
println!("Random Number: {}", random_number);
//random bool
let random_bool = rand::thread_rng().gen_bool(1.0/2.0);
println!("Random Boolean: {}", random_bool);
}
Even tho i have rand crate in the dependencies it is still saying that it cannot find the crate
For those curious, gen_weighted_bool() is no longer avaliable in the rand crate, you need to use gen_bool(), which takes a floating-point probability from 0.0 to 1.0
Hi all, Deprecated since 0.5.0: use gen_bool instead - rand::thread_rng().gen_bool(1.0 / 3.0);
thank you for this but my eyes no longer work can you make a video about that
how to use magic_number() function to generate unsigned values (0 or 1)
how to make matrix with random numbers?
good lessons, tnx