PHPackages                             infocyph/game-draw - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. infocyph/game-draw

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

infocyph/game-draw
==================

Generates Item and Item count for winners.

3.1(1y ago)144.6k↓50%1[1 PRs](https://github.com/infocyph/Game-Draw/pulls)MITPHPPHP &gt;=8.0CI failing

Since Sep 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/infocyph/Game-Draw)[ Packagist](https://packagist.org/packages/infocyph/game-draw)[ RSS](/packages/infocyph-game-draw/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (15)Used By (0)

Game Draw
=========

[](#game-draw)

[![Codacy Badge](https://camo.githubusercontent.com/d90d8fef042f38cbb3da33a08b73e2f058c6c041b8cd92498ba53a2bf488dfd2/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3164303439393265666166653461656361336333623134626537343736613530)](https://app.codacy.com/gh/infocyph/Game-Draw/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![Libraries.io dependency status for GitHub repo](https://camo.githubusercontent.com/77491d923bf6ab1b836469275b5690dfcb5c7127b799ce495e513de82339df7d/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f696e666f637970682f67616d652d64726177)](https://camo.githubusercontent.com/77491d923bf6ab1b836469275b5690dfcb5c7127b799ce495e513de82339df7d/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f696e666f637970682f67616d652d64726177)[![Packagist Downloads](https://camo.githubusercontent.com/0e7f17a434ac17098cb15105878248b0a93ce2a2d42212c182e6f5c8d37fd291/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e666f637970682f67616d652d64726177)](https://camo.githubusercontent.com/0e7f17a434ac17098cb15105878248b0a93ce2a2d42212c182e6f5c8d37fd291/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e666f637970682f67616d652d64726177)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)[![Packagist Version](https://camo.githubusercontent.com/31ebd242e8f9ef9c22ed294200dfc67e41049aafef364092ac27a0a51702ef8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e666f637970682f67616d652d64726177)](https://camo.githubusercontent.com/31ebd242e8f9ef9c22ed294200dfc67e41049aafef364092ac27a0a51702ef8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e666f637970682f67616d652d64726177)[![Packagist PHP Version Support](https://camo.githubusercontent.com/98de8124fa834dfd6f2dd3f0acfa36c92a999054ee28bcf2a1a112411e92ccc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e666f637970682f67616d652d64726177)](https://camo.githubusercontent.com/98de8124fa834dfd6f2dd3f0acfa36c92a999054ee28bcf2a1a112411e92ccc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e666f637970682f67616d652d64726177)[![GitHub code size in bytes](https://camo.githubusercontent.com/d69c6f1b355f0e431a246d300202a052caa2608baf4bb0791ea62153a942a716/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f696e666f637970682f67616d652d64726177)](https://camo.githubusercontent.com/d69c6f1b355f0e431a246d300202a052caa2608baf4bb0791ea62153a942a716/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f696e666f637970682f67616d652d64726177)

The **Game Draw** library provides flexible and varied methods for selecting winners based on different types of draws, **Lucky Draw**, **Grand Draw**, and a customizable **Flexible Draw** to meet a range of requirements.

> Please don't use this to generate things/prizes with People's hard-earned money. It is intended to make things fun with bonus gifts only.

Prerequisites
-------------

[](#prerequisites)

- **Language:** PHP 8+
- **PHP Extension:** BCMath (may need to install manually)

Installation
------------

[](#installation)

```
composer require infocyph/game-draw

```

Overview
--------

[](#overview)

### 1. LuckyDraw

[](#1-luckydraw)

The `LuckyDraw` class allows for winner selection based on item chances and weighted amounts.

#### Input Data

[](#input-data)

```
$products = [
    [
        'item' => 'product_000_NoLuck', // Item code or Identifier
        'chances' => '100000',          // Item Chances
        'amounts'=> [ 1 ]              // Item Amounts
    ],
    [
        'item' => 'product_001',
        'chances' => '1000',
        'amounts' => '1.5,10.00001,1'    // Weighted CSV formatted range (min,max,bias)
    ],
    [
        'item' => 'product_002',
        'chances' => '500.001',         // Fraction Allowed
        'amounts' => [
            1 => 100,                   // Amount chances
            5 => 50,                    // Format: Amount => Chances
            10 => 10.002,               // Fraction allowed
        ]
    ],
    [
        'item' => 'product_003',
        'chances' => '100',
        'amounts' => [
            1 => 100,
            5 => 50,
            10 => 10,
            20 => 5,
        ]
    ],
    [
        'item' => 'product_004',
        'chances' => '1',
        'amounts' => [ 10, 15, 30, 50 ] // Amounts without probability
    ],
]
```

- **item**: Provide your item's unique identifier
- **chances**: Weight of item (Float/Int).

    - It will be compared along all the items in array.
    - The higher the chances the greater the chances of getting the item.
    - In case of active inventory you can pass available item stock here
- **amounts**: String or Array of Item amount (Float/Int). It can be any like:

    - (array) Single Positive value, i.e. \[ 1 \] or Multiple Positive value (randomly picked), i.e. \[ 1, 2, 3, 5\]
    - (array) Weighted amount, i.e. ```
        [
            5 => 100,
            15 => 50,
            50 => 10,
            80 => 5.001
        ]
        ```
    - (String) Weighted CSV formatted range (min,max,bias) `'1,10.00001,0.001'`
        - Only 3 members allowed in CSV format **min,max,bias**
        - Max should be greater than or equal to min, bias should be greater than 0
        - The higher the bias, the more the chance to pick the lowest amount

#### Usage

[](#usage)

```
$luckyDraw = new AbmmHasan\Draw\LuckyDraw($products);
$result = $luckyDraw->pick();
```

Example Output:

```
[
    'item' => 'product_000_NoLuck',
    'amount' => 1
]
```

> Inventory Solutions: Available stock should be passed (after subtracting used amount from stock amount) in chances properly.

### 2. GrandDraw

[](#2-granddraw)

The `GrandDraw` class is designed for large draws where items and user entries are managed in bulk.

#### Input Data

[](#input-data-1)

```
$prizes =
[
    'product_001'=>50,        // Item Code/Identifier => Amount of the item
    'product_002'=>5,
    'product_003'=>3,
    'product_004'=>2,
    'product_005'=>1
];
```

- **item**: Provide your item's unique identifier
- **amounts**: Amount of gift. It must be a positive integer value.

User entries are loaded using a CSV file:

```
"usr47671",
"usr57665",
"usr47671",
.....
```

#### Usage

[](#usage-1)

```
$grandDraw = new AbmmHasan\Draw\GrandDraw();
$grandDraw->setItems($prizes)
          ->setUserListFilePath('./Sample1000.csv');
$winners = $grandDraw->getWinners();
```

Example Output:

```
[
    'product_001' => ['usr47671', 'usr57665', 'usr92400'],
    'product_002' => ['usr50344', 'usr60450', 'usr62662']
]
```

### 3. FlexibleDraw

[](#3-flexibledraw)

The `FlexibleDraw` class provides a versatile approach to selection, offering various types of draw methods, including probability-based, elimination, round-robin, time-based, and more. This flexibility allows for customized and dynamic draws, suitable for a range of applications.

#### Supported Draw Types

[](#supported-draw-types)

- **Probability Draw**: Selects items based on assigned probability weights.
- **Elimination Draw**: Items are drawn and removed from the selection pool, ensuring no repeats.
- **Weighted Elimination Draw**: Similar to Elimination Draw, but selections are weighted.
- **Round Robin Draw**: Items are selected in a round-robin sequence, cycling through each item.
- **Cumulative Draw**: Draws items based on cumulative scores, with higher scores increasing selection probability.
- **Batched Draw**: Draws a specified number of items in one call, with or without replacement.
- **Time-Based Weighted Draw**: Selects items based on weight and a specified time interval, e.g., daily or weekly.
- **Weighted Batch Draw**: Draws a batch of items using weighted probabilities.
- **Sequential Draw**: Draws items in a fixed sequence, restarting once all items are drawn.
- **Range Weighted Draw**: Selects a random number within a defined range, weighted by probability.

#### FlexibleDraw Options and Usage Examples

[](#flexibledraw-options-and-usage-examples)

Below are usage examples for each draw type. Define your items array based on the draw type requirements.

1. **Probability Draw**:

    - Selects items based on weighted probabilities. Higher-weight items have a greater likelihood of selection.

    ```
    $items = [
        ['name' => 'item1', 'weight' => 10],
        ['name' => 'item2', 'weight' => 20],
    ];
    ```
2. **Elimination Draw**:

    - Items are drawn once, removed from the pool after selection.

    ```
    $items = [
        ['name' => 'item1'],
        ['name' => 'item2'],
    ];
    ```
3. **Weighted Elimination Draw**:

    - Similar to elimination, but uses weights to influence item selection.

    ```
    $items = [
        ['name' => 'item1', 'weight' => 10],
        ['name' => 'item2', 'weight' => 20],
    ];
    ```
4. **Round Robin Draw**:

    - Cycles through items in a round-robin sequence.

    ```
    $items = [
        ['name' => 'item1'],
        ['name' => 'item2'],
    ];
    ```
5. **Cumulative Draw**:

    - Draws items based on cumulative scores, with selection probabilities adjusted over time.

    ```
    $items = [
        ['name' => 'item1'],
        ['name' => 'item2'],
    ];
    ```
6. **Batched Draw**:

    - Draws a batch of items in one call, with optional replacement.

    ```
    $items = [
        ['name' => 'item1'],
        ['name' => 'item2'],
    ];
    ```
7. **Time-Based Weighted Draw**:

    - Selects items based on weight and a specified time interval (e.g., daily or weekly).

    ```
    $items = [
        ['name' => 'item1', 'weight' => 10, 'time' => 'daily'],
        ['name' => 'item2', 'weight' => 20, 'time' => 'weekly'],
    ];
    ```
8. **Weighted Batch Draw**:

    - Draws a batch of items using weighted probabilities, balancing selections by item weight.

    ```
    $items = [
        ['name' => 'item1', 'weight' => 10],
        ['name' => 'item2', 'weight' => 20],
    ];
    ```
9. **Sequential Draw**:

    - Selects items in a predefined sequence.

    ```
    $items = [
        ['name' => 'item1'],
        ['name' => 'item2'],
    ];
    ```
10. **Range Weighted Draw**:

    - Specifies a range for each item using `min`, `max`, and `weight`.

    ```
    $items = [
        ['name' => 'item1', 'min' => 1, 'max' => 50, 'weight' => 10],
        ['name' => 'item2', 'min' => 5, 'max' => 25, 'weight' => 15],
    ];
    ```

#### Usage

[](#usage-2)

To use the `FlexibleDraw` class, create an instance with your items array and specify the draw type in the `draw`method:

```
$flexibleDraw = new FlexibleDraw($items);
$result = $flexibleDraw->draw('drawType'); // Replace 'drawType' with the desired draw type, e.g., 'probability'
```

### Example Output

[](#example-output)

The output depends on the draw type and item configuration. For example, a probability draw with weights might yield:

```
[
    'item' => 'item2',
    'weight' => 20,
]
```

### FlexibleDraw Configuration Summary

[](#flexibledraw-configuration-summary)

The `FlexibleDraw` class is highly adaptable, supporting various selection methods and configurations such as `weight`, `group`, `min`, `max`, and `time`. Ideal for applications needing nuanced and dynamic draws, it is more versatile than simpler draw mechanisms but optimized for manageable volumes.

Support
-------

[](#support)

Having trouble? Create an issue!

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~125 days

Recently: every ~84 days

Total

13

Last Release

556d ago

Major Versions

1.06 → 2.02023-12-06

2.01.1 → 3.02024-11-08

PHP version history (2 changes)1.0PHP &gt;=7.0

2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/33b750b84ab22f2038ef9b90ee48f2fcdaab6b5698e9f956a89a152466200b63?d=identicon)[abmmhasan](/maintainers/abmmhasan)

---

Top Contributors

[![abmmhasan](https://avatars.githubusercontent.com/u/7711128?v=4)](https://github.com/abmmhasan "abmmhasan (40 commits)")

---

Tags

chancechancesdrawgame-drawgiftsitem-countjackpotlotteryluckluckymegaphpprizestockweighted-distributionsweighted-probabilityweighted-random

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/infocyph-game-draw/health.svg)

```
[![Health](https://phpackages.com/badges/infocyph-game-draw/health.svg)](https://phpackages.com/packages/infocyph-game-draw)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
