Download the PHP package infocyph/game-draw without Composer
On this page you can find all versions of the php package infocyph/game-draw. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download infocyph/game-draw
More information about infocyph/game-draw
Files in infocyph/game-draw
Package game-draw
Short Description Generates Item and Item count for winners.
License MIT
Informations about the package game-draw
Game Draw
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
- Language: PHP 8+
- PHP Extension: BCMath (may need to install manually)
Installation
Overview
1. LuckyDraw
The LuckyDraw
class allows for winner selection based on item chances and weighted amounts.
Input Data
-
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.
- (String) Weighted CSV formatted range (min,max,bias)
- 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
Example Output:
Inventory Solutions: Available stock should be passed (after subtracting used amount from stock amount) in chances properly.
2. GrandDraw
The GrandDraw
class is designed for large draws where items and user entries are managed in bulk.
Input Data
-
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:
Usage
Example Output:
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
- 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
Below are usage examples for each draw type. Define your items array based on the draw type requirements.
-
Probability Draw:
- Selects items based on weighted probabilities. Higher-weight items have a greater likelihood of selection.
-
Elimination Draw:
- Items are drawn once, removed from the pool after selection.
-
Weighted Elimination Draw:
- Similar to elimination, but uses weights to influence item selection.
-
Round Robin Draw:
- Cycles through items in a round-robin sequence.
-
Cumulative Draw:
- Draws items based on cumulative scores, with selection probabilities adjusted over time.
-
Batched Draw:
- Draws a batch of items in one call, with optional 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, balancing selections by item weight.
-
Sequential Draw:
- Selects items in a predefined sequence.
- Range Weighted Draw:
- Specifies a range for each item using
min
,max
, andweight
.
- Specifies a range for each item using
Usage
To use the FlexibleDraw
class, create an instance with your items array and specify the draw type in the draw
method:
Example Output
The output depends on the draw type and item configuration. For example, a probability draw with weights might yield:
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
Having trouble? Create an issue!
All versions of game-draw with dependencies
ext-bcmath Version *