Random Deck
Randomness without replacement. Draw from a shuffled deck instead of rolling dice to reduce frustrating streaks.
com.ethankennerly.randomdeck Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/randomdeck.git README Markdown
Copy this to your project's README.md
## Installation
Add **Random Deck** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/randomdeck.git
```
[](https://www.pkglnk.dev/pkg/randomdeck)README
Random Deck
Randomness without replacement. Draw from a shuffled deck instead of rolling dice to reduce frustrating streaks.
Inspired by Randomness without Replacement.
Purpose
When designing games, random events often produce frustrating streaks. Ten misses in a row with a 50% hit chance is unlikely but inevitable given enough players. Drawing cards from a deck instead of rolling dice guarantees that after enough draws, every outcome appears. This package provides a generic deck that shuffles and draws without replacement.
Usage
using EthanKennerly.RandomDeck;
var random = new SystemRandom();
var cards = new int[] { 1, 2, 3, 4, 5 };
var deck = new Deck<int>(random, cards);
deck.Shuffle();
int card = deck.Draw();
Prevent Recent Repetition
Set MinDrawsBetweenRepetition to prevent the same card from
appearing too soon after it was last drawn. Default is 0, which
behaves like a standard deck. Setting it to 1 prevents the same
card from appearing on consecutive draws across reshuffles.
deck.MinDrawsBetweenRepetition = 1;
Installation
Install via the Unity Package Manager:
- Open your project in Unity.
- Open the Package Manager (Window > Package Manager).
- Click the + button and select "Add package from git URL..."
- Enter:
https://github.com/ethankennerly/random-deck-unity.git
Compatibility
- Unity 6.3 and later
- AOT platforms (iOS, WebGL)
- No reflection, no LINQ
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In