coin_flip

Crates.iocoin_flip
lib.rscoin_flip
version0.1.1
created_at2025-09-17 06:40:07.445007+00
updated_at2025-09-17 06:46:02.69196+00
descriptionA library for flipping a coin and getting the result.
homepagehttps://github.com/OmniKobra/coin_flip_rust
repositoryhttps://github.com/OmniKobra/coin_flip_rust
max_upload_size
id1842834
size11,480
Omar (OmniKobra)

documentation

https://docs.rs/coin_flip/0.1.0/coin_flip/

README

🪙 Coin Flip Simulator

A simple Rust program that simulates flipping a fair coin multiple times and reports the results with percentages.


✨ Features

  • Simulates flipping a coin (Heads or Tails).
  • Keeps track of the number of times each side comes up.
  • Calculates percentages of outcomes.
  • Uses closures to handle coin flip events flexibly.

📦 Requirements

  • Rust (edition 2021 or newer)
  • rand crate

Add rand to your Cargo.toml:

[dependencies]
rand = "0.9.2"

▶️ Usage

Clone the repository and run the program:

cargo run

Example output:

Out of 100:
Heads: 50 (50.00%)
Tails: 50 (50.00%)

🛠 Project Structure

src/
├── lib.rs   # Library code (coin enum, flip logic, percentage calculation)
└── main.rs  # Entry point, runs the simulation

📖 How It Works

  1. flip_coin generates a random Heads or Tails.
  2. A closure (handler) processes the result (e.g., counting outcomes).
  3. After all runs, the program calculates and prints percentages.

🔮 Possible Improvements

  • Add support for multiple coins at once.
  • Write unit tests for the coin flip logic.
  • Provide a histogram of results for large runs.

📜 License

This project is open source and available under the MIT License.

Commit count: 9

cargo fmt