coin_flip 0.1.0

A library for flipping a coin and getting the result.
Documentation
  • Coverage
  • 50%
    3 out of 6 items documented1 out of 3 items with examples
  • Size
  • Source code size: 10.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.47 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 22s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • OmniKobra/coin_flip_rust
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • OmniKobra

🪙 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.