Skip to content

Instantly share code, notes, and snippets.

@barseghyanartur
Created February 6, 2023 11:36
Show Gist options
  • Save barseghyanartur/9566e4bc990cdac737c8532a4058e97b to your computer and use it in GitHub Desktop.
Save barseghyanartur/9566e4bc990cdac737c8532a4058e97b to your computer and use it in GitHub Desktop.
Rust random boolean

Random boolean in Rust

Prerequisites

[dependencies]
rand = "0.8.5"

Usage example

use rand::Rng;
let mut rng = rand::thread_rng();
let choice: bool = rng.gen();  // This is the random value
@siennathesane
Copy link

this won't work in rust 2024, as a head's up. rng changed the api and the rust lang team reserved the gen keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment