You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+169-78
Original file line number
Diff line number
Diff line change
@@ -9,26 +9,28 @@
9
9

10
10
11
11
12
-
The Game Draw library provides 2 different way of winner selection based on user's input and selected method.
12
+
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.
13
13
14
14
> 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.
15
15
16
16
17
-
## Prerequisits
17
+
## Prerequisites
18
18
19
-
Language: PHP 8/+
20
-
21
-
PHP Extension: BCMath (may need to install manually)
19
+
-**Language:** PHP 8+
20
+
-**PHP Extension:** BCMath (may need to install manually)
22
21
23
22
## Installation
24
23
25
24
```
26
-
composer require abmmhasan/game-draw
25
+
composer require infocyph/game-draw
27
26
```
27
+
## Overview
28
+
29
+
### 1. LuckyDraw
28
30
29
-
## Usage (Lucky Draw)
31
+
The `LuckyDraw` class allows for winner selection based on item chances and weighted amounts.
30
32
31
-
### Input Data
33
+
####Input Data
32
34
33
35
```php
34
36
$products = [
@@ -92,28 +94,29 @@ $products = [
92
94
- Max should be greater than or equal to min, bias should be greater than 0
93
95
- The higher the bias, the more the chance to pick the lowest amount
94
96
95
-
### Output Data
97
+
#### Usage
96
98
97
99
```php
98
100
$luckyDraw = new AbmmHasan\Draw\LuckyDraw($products);
99
-
$luckyDraw->pick()
101
+
$result = $luckyDraw->pick();
100
102
```
101
-
Will output the data similar as following,
103
+
104
+
Example Output:
102
105
103
106
```php
104
107
[
105
-
'item' => 'product_000_NoLuck', // The item name
106
-
'amount' => 1 // the selected amount
108
+
'item' => 'product_000_NoLuck',
109
+
'amount' => 1
107
110
]
108
111
```
109
112
110
-
###Inventory Solutions
113
+
>Inventory Solutions: Available stock should be passed (after subtracting used amount from stock amount) in chances properly.
111
114
112
-
Available stock should be passed (after subtracting used amount from stock amount) in chances properly.
115
+
### 2. GrandDraw
113
116
114
-
## Usage (Grand Draw)
117
+
The `GrandDraw` class is designed for large draws where items and user entries are managed in bulk.
115
118
116
-
### Input Data
119
+
####Input Data
117
120
118
121
```php
119
122
$prizes =
@@ -130,79 +133,167 @@ $prizes =
130
133
131
134
-**amounts**: Amount of gift. It must be a positive integer value.
132
135
133
-
To pass users, you've to make a CSV file with at-least 1 column. 1st column will indicate user identity.
136
+
User entries are loaded using a CSV file:
134
137
135
138
```csv
136
139
"usr47671",
137
140
"usr57665",
138
-
"usr47671",.....
141
+
"usr47671",
142
+
.....
139
143
```
140
144
141
-
###Output Data
145
+
#### Usage
142
146
143
147
```php
144
-
$bucket = new GrandDraw();
145
-
146
-
// set resources
147
-
$bucket->setItems([ // set prizes
148
-
'product_001' => 10, // Item Code/Identifier => Amount of the item
149
-
'product_002' => 5,
150
-
'product_003' => 3,
151
-
'product_004' => 2,
152
-
'product_005' => 1
153
-
])->setUserListFilePath('./Sample1000.csv'); // set the CSV file location
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.
166
+
167
+
#### Supported Draw Types
168
+
-**Probability Draw**: Selects items based on assigned probability weights.
169
+
-**Elimination Draw**: Items are drawn and removed from the selection pool, ensuring no repeats.
170
+
-**Weighted Elimination Draw**: Similar to Elimination Draw, but selections are weighted.
171
+
-**Round Robin Draw**: Items are selected in a round-robin sequence, cycling through each item.
172
+
-**Cumulative Draw**: Draws items based on cumulative scores, with higher scores increasing selection probability.
173
+
-**Batched Draw**: Draws a specified number of items in one call, with or without replacement.
174
+
-**Time-Based Weighted Draw**: Selects items based on weight and a specified time interval, e.g., daily or weekly.
175
+
-**Weighted Batch Draw**: Draws a batch of items using weighted probabilities.
176
+
-**Sequential Draw**: Draws items in a fixed sequence, restarting once all items are drawn.
177
+
-**Range Weighted Draw**: Selects a random number within a defined range, weighted by probability.
178
+
179
+
#### FlexibleDraw Options and Usage Examples
180
+
181
+
Below are usage examples for each draw type. Define your items array based on the draw type requirements.
182
+
183
+
1.**Probability Draw**:
184
+
- Selects items based on weighted probabilities. Higher-weight items have a greater likelihood of selection.
185
+
```php
186
+
$items = [
187
+
['name' => 'item1', 'weight' => 10],
188
+
['name' => 'item2', 'weight' => 20],
189
+
];
190
+
```
191
+
192
+
2.**Elimination Draw**:
193
+
- Items are drawn once, removed from the pool after selection.
194
+
```php
195
+
$items = [
196
+
['name' => 'item1'],
197
+
['name' => 'item2'],
198
+
];
199
+
```
200
+
201
+
3.**Weighted Elimination Draw**:
202
+
- Similar to elimination, but uses weights to influence item selection.
203
+
```php
204
+
$items = [
205
+
['name' => 'item1', 'weight' => 10],
206
+
['name' => 'item2', 'weight' => 20],
207
+
];
208
+
```
209
+
210
+
4.**Round Robin Draw**:
211
+
- Cycles through items in a round-robin sequence.
212
+
```php
213
+
$items = [
214
+
['name' => 'item1'],
215
+
['name' => 'item2'],
216
+
];
217
+
```
218
+
219
+
5.**Cumulative Draw**:
220
+
- Draws items based on cumulative scores, with selection probabilities adjusted over time.
221
+
```php
222
+
$items = [
223
+
['name' => 'item1'],
224
+
['name' => 'item2'],
225
+
];
226
+
```
227
+
228
+
6.**Batched Draw**:
229
+
- Draws a batch of items in one call, with optional replacement.
230
+
```php
231
+
$items = [
232
+
['name' => 'item1'],
233
+
['name' => 'item2'],
234
+
];
235
+
```
236
+
237
+
7.**Time-Based Weighted Draw**:
238
+
- Selects items based on weight and a specified time interval (e.g., daily or weekly).
To use the `FlexibleDraw` class, create an instance with your items array and specify the draw type in the `draw` method:
276
+
277
+
```php
278
+
$flexibleDraw = new FlexibleDraw($items);
279
+
$result = $flexibleDraw->draw('drawType'); // Replace 'drawType' with the desired draw type, e.g., 'probability'
280
+
```
281
+
282
+
### Example Output
283
+
284
+
The output depends on the draw type and item configuration. For example, a probability draw with weights might yield:
285
+
286
+
```php
287
+
[
288
+
'item' => 'item2',
289
+
'weight' => 20,
290
+
]
291
+
```
292
+
293
+
### FlexibleDraw Configuration Summary
294
+
295
+
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.
0 commit comments