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
The Laravel Secure Random Number Generator package has been enhanced with several new methods and trait to provide more flexibility and functionality when generating secure random numbers.
81
+
82
+
## New Methods
83
+
84
+
### Batch Generation
85
+
```php
86
+
/**
87
+
* Generates multiple secure random numbers within the configured range.
88
+
*
89
+
* @param int $count Number of unique random numbers to generate
90
+
* @return array<int> Array of unique secure random numbers
91
+
*
92
+
* @throws RuntimeException If unable to generate enough unique numbers
93
+
*/
94
+
public function generateBatch(int $count): array;
95
+
```
96
+
97
+
### Formatted Numbers
98
+
```php
99
+
/**
100
+
* Generates a secure random number with optional prefix and suffix.
101
+
*
102
+
* @param string $prefix String to prepend to the number
103
+
* @param string $suffix String to append to the number
104
+
* @return string Formatted random number with prefix and suffix
105
+
*/
106
+
public function generateFormatted(string $prefix = '', string $suffix = ''): string;
107
+
```
108
+
109
+
### Pattern-Based Numbers
110
+
```php
111
+
/**
112
+
* Generates a secure random number formatted according to a pattern.
113
+
*
114
+
* The pattern uses # as a placeholder for each digit.
115
+
* Example: "###-###" might produce "123-456"
116
+
*
117
+
* @param string $pattern Format pattern with # as digit placeholders
118
+
* @return string Formatted random number
119
+
*
120
+
* @throws RuntimeException If pattern is invalid or number generation fails
121
+
*/
122
+
public function generateWithPattern(string $pattern): string;
123
+
```
124
+
125
+
### Batch Formatted Numbers
126
+
```php
127
+
/**
128
+
* Generates multiple secure random numbers with optional prefix and suffix.
129
+
*
130
+
* @param int $count Number of unique random numbers to generate
131
+
* @param string $prefix String to prepend to each number
132
+
* @param string $suffix String to append to each number
133
+
* @return array<string> Array of formatted unique secure random numbers
134
+
*
135
+
* @throws RuntimeException If unable to generate enough unique numbers
136
+
*/
137
+
public function generateBatchFormatted(int $count, string $prefix = '', string $suffix = ''): array;
138
+
```
139
+
140
+
### Batch Pattern-Based Numbers
141
+
```php
142
+
/**
143
+
* Generates multiple secure random numbers formatted according to a pattern.
144
+
*
145
+
* @param int $count Number of unique random numbers to generate
146
+
* @param string $pattern Format pattern with # as digit placeholders
147
+
* @return array<string> Array of formatted unique secure random numbers
148
+
*
149
+
* @throws RuntimeException If unable to generate enough unique numbers
150
+
*/
151
+
public function generateBatchWithPattern(int $count, string $pattern): array;
152
+
```
153
+
154
+
### Range Customization
155
+
```php
156
+
/**
157
+
* Sets the minimum value for the random number range.
158
+
*
159
+
* @param int $min The minimum value (inclusive)
160
+
*/
161
+
public function min(int $min): self;
162
+
163
+
/**
164
+
* Sets the maximum value for the random number range.
165
+
*
166
+
* @param int $max The maximum value (inclusive)
167
+
*/
168
+
public function max(int $max): self;
169
+
```
170
+
171
+
### Uniqueness Validation
172
+
```php
173
+
/**
174
+
* Sets the table and column for uniqueness validation.
175
+
*
176
+
* @param string $table The database table name
177
+
* @param string $column The column name in the table
178
+
*/
179
+
public function uniqueIn(string $table, string $column): self;
// Result: "ORD-123-2023" (unique in orders.order_number)
245
+
```
246
+
247
+
## Error Handling
248
+
The batch generation methods will throw a RuntimeException if they cannot generate the requested number of unique values after a reasonable number of attempts.
0 commit comments