Skip to content

Implement random.coinFlip() and random.coinFlipAsync()#99

Merged
Smoren merged 1 commit into
Smoren:devfrom
Akashrana1001:feature/random-coin-flip
Jul 10, 2026
Merged

Implement random.coinFlip() and random.coinFlipAsync()#99
Smoren merged 1 commit into
Smoren:devfrom
Akashrana1001:feature/random-coin-flip

Conversation

@Akashrana1001

Copy link
Copy Markdown
Contributor

Summary

Closes #77

Implements the random.coinFlip() family of functions as described in the issue:

  • random.coinFlip(repetitions?) — sync generator yielding 0 or 1 randomly
  • random.coinFlipAsync(repetitions?) — async version
  • Stream.ofCoinFlip(repetitions?) — fluent stream factory
  • AsyncStream.ofCoinFlip(repetitions?) — async stream factory

Implementation notes

  • Follows the identical pattern as random.percentage() / random.booleans()
  • Iterates infinitely when repetitions is omitted; terminates after exactly repetitions values otherwise
  • Throws InvalidArgumentError for negative repetitions, consistent with the rest of the module

Test plan

  • Finite sync: yields exactly N values, each 0 or 1
  • Infinite sync: can pull N values from an unbounded generator
  • Negative sync: throws InvalidArgumentError
  • Finite async: same as sync counterpart
  • Infinite async: same as sync counterpart
  • Negative async: rejects with InvalidArgumentError
  • Stream.ofCoinFlip(): correct count + values, works with .limit()
  • AsyncStream.ofCoinFlip(): correct count + values, works with .limit()
  • Full test suite: 28,373 tests passing, 100% coverage on all source files

🤖 Generated with Claude Code

Adds coinFlip/coinFlipAsync generators that yield 0 or 1 randomly,
with optional repetitions param (infinite if omitted). Also adds
Stream.ofCoinFlip() and AsyncStream.ofCoinFlip() factory methods.

Closes Smoren#77

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Akashrana1001

Copy link
Copy Markdown
Contributor Author

Hi @Smoren, the PR is ready for review. Could you approve the workflow run when you get a chance? Happy to make any changes you need.

@Smoren
Smoren changed the base branch from master to dev July 9, 2026 21:35
@Smoren
Smoren merged commit 307cfa4 into Smoren:dev Jul 10, 2026
1 check passed
@Smoren

Smoren commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Hi @Akashrana1001
Thznk you for your PR! I merged it. The changes will be included in the next release.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement random.coinFlip()

2 participants