SDD experiment using speckit
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-18 17:16:49 -04:00
.omp/commands add speckit 2026-10-18 17:16:49 -04:00
.specify add speckit 2026-10-18 17:16:49 -04:00
.mcp.json add mcp config 2026-10-18 16:31:35 -04:00
README.md initial project 2026-10-18 16:26:05 -04:00

Mega Millions Quick Pick CLI

Generate cryptographically secure random lottery numbers for the Mega Millions game.

Overview

A command-line application that produces one Mega Millions ticket (5 white balls + 1 Megaball).

Project Setup

cargo init . --name megamillions --edition 2024

Game Rules

  • White balls: 5 unique numbers from 1–70
  • Mega Ball: 1 number from 1–24 (independent of white balls)

Interface

Invocation

megamillions
  • No arguments accepted; any provided arguments MUST be ignored

Output Format

Quick Picks: <w1> <w2> <w3> <w4> <w5>
Mega Ball: <mb>
  • First line starts with Quick Picks: (space-separated white balls, sorted ascending)
  • Second line starts with Mega Ball: (single integer 1–24)
  • Example:
    Quick Picks: 7 19 34 51 63
    Mega Ball: 18
    

Implementation Requirements

  • Language: Rust
  • Arguments: Any arguments passed to the application should be silently ignored
  • Cryptographic RNG: Use rand::rngs::SysRng (rand 0.10 successor of OsRng) or equivalent; NOT a seeded PRNG
  • White balls: Must be unique; generation strategy should avoid rejection sampling inefficiency
  • Code style: Follow cargo clippy + rustfmt (no warnings)

Coding Standards

SOLID Principles

Apply SOLID principles where applicable to this small CLI:

  • Single Responsibility: Each function should have one reason to change (e.g., separate concerns: RNG, validation, formatting)
  • Open/Closed: Prefer extensible designs (e.g., abstracted RNG interface if future plug-in strategies emerge)
  • Liskov Substitution: Trait implementations must satisfy their contracts faithfully
  • Interface Segregation: Avoid overly broad trait boundaries; prefer focused interfaces
  • Dependency Inversion: Depend on abstractions (e.g., rand::RngCore trait) rather than concrete RNG implementations

Rust Best Practices

  • Error handling: Use Result and ? operator; avoid unwrap() except where panic is justified (document why)
  • Ownership & borrowing: Minimize clones; prefer references and iterators
  • Idiomatic code: Leverage iterators, pattern matching, and Rust's type system
  • Safety: No unsafe blocks unless absolutely necessary (document invariants)
  • Dependencies: Keep minimal; justify each external crate

Code Duplication

  • DRY in implementation: Extract common logic into reusable functions (e.g., shared validation, formatting)
  • DRY in tests: Use helper functions and fixtures for repeated test setup; avoid copy-pasted assertions
  • Constants: Define magic numbers (1, 70, 24) as named constants at module level

Testing Strategy

Scope

  • Valid output structure (line count, format, ranges)
  • Uniqueness of white balls
  • Range validation (white: 1–70, mega: 1–24)
  • RNG entropy (statistical tests optional; use rand library's assumed correctness)

Not in scope

  • Performance benchmarks
  • Distribution uniformity (trust rand crate)

Build & Run

cargo build --release
./target/release/megamillions