Skip to content

About

A fluent PHP utility class to help create random values.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

51 Commits

Folders and files

Repository files navigation

Random Utilities

A fluent PHP utility class to help create random values.

⚠ Characters are sampled with PHP's random_bytes() (the OS CSPRNG) using rejection sampling, so selection from the pool is unbiased. Duplicate pool entries and output constraints change the distribution (see Usage). The package has not been independently audited; assess it against your own security requirements before using it for passwords or tokens.

Latest Stable Version Total Downloads PHP Version Require License Tests codecov

Requirements

  • PHP 8.5+

Install

composer require myerscode/utilities-random

Usage

use Myerscode\Utilities\Random\Drivers\AlphaNumericDriver;
use Myerscode\Utilities\Random\Utility;

$utility = new Utility(AlphaNumericDriver::class);

// Generate a random string of length 5
$random = $utility->generate();

// Generate with custom length
$random = $utility->length(10)->generate();

// Generate chunked values
$random = $utility->length(4)->chunks(3)->spacer('-')->generate();
// e.g. "aB3x-Kp9z-mN2q"

// Generate unique values
$unique = $utility->length(10)->unique();

Documentation

  • Usage — full API reference and usage examples
  • Drivers — built-in drivers and creating custom ones
  • Constraints — constraining generation with pool filters and output constraints

License

MIT

About

A fluent PHP utility class to help create random values.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages