-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baa382b
commit d30d816
Showing
1 changed file
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,102 @@ | ||
# random | ||
# Random | ||
|
||
An PHP tool for generate random values easily. | ||
|
||
## Requirements | ||
|
||
PHP >= 8.2 | ||
|
||
## Installation | ||
via Composer: | ||
``` | ||
composer require alirezasalehizadeh/random | ||
``` | ||
|
||
|
||
## Usage | ||
#### Integer | ||
```php | ||
use Alirezasalehizadeh\Random; | ||
|
||
|
||
// Generate an random int | ||
(new Random)->randomInt(): int | ||
|
||
// Pick an random int between min and max | ||
(new Random)->pickInt($min, $max): int | ||
``` | ||
#### String | ||
```php | ||
use Alirezasalehizadeh\Random; | ||
|
||
|
||
// Generate an random string with specific length | ||
(new Random)->randomString(int $length): string | ||
|
||
// Generate an random string from given string | ||
(new Random)->pickString(string $bytes): string | ||
``` | ||
#### Array | ||
```php | ||
use Alirezasalehizadeh\Random; | ||
|
||
|
||
// Generate an random array from given array | ||
(new Random)->randomArray(array $array): array | ||
|
||
// Pick random elements from given array | ||
(new Random)->choice(array $array, int $num): array | ||
``` | ||
### Engines | ||
You can use engines in `/Engines` for generate random string values: | ||
#### Mt19937(Mersenne Twister) | ||
```php | ||
use Alirezasalehizadeh\Random; | ||
use Alirezasalehizadeh\Random\Engines\MersenneTwisterEngine; | ||
|
||
|
||
(new Random(new MersenneTwisterEngine))->getEngine()->generate(): string | ||
|
||
``` | ||
#### PcgOneseq128XslRr64 | ||
```php | ||
use Alirezasalehizadeh\Random; | ||
use Alirezasalehizadeh\Random\Engines\PCGEngine; | ||
|
||
|
||
(new Random(new PCGEngine))->getEngine()->generate(): string | ||
|
||
``` | ||
#### Xoshiro256StarStar | ||
```php | ||
use Alirezasalehizadeh\Random; | ||
use Alirezasalehizadeh\Random\Engines\XoshiroEngine; | ||
|
||
|
||
(new Random(new XoshiroEngine))->getEngine()->generate(): string | ||
|
||
``` | ||
### Facades | ||
```php | ||
use Alirezasalehizadeh\Random\Facades\Random; | ||
|
||
Random::randomInt(): int | ||
Random::pickInt($min, $max): int | ||
|
||
Random::randomString(int $length): string | ||
Random::pickString(string $bytes): string | ||
|
||
Random::randomArray(array $array): array | ||
Random::choice(array $array, int $num): array | ||
|
||
``` | ||
|
||
|
||
## Contributing | ||
Send pull request or open issue for contributing. | ||
|
||
|
||
## License | ||
|
||
[MIT](LICENSE). | ||
|