RealRandom
in package
implements
IRandom
Real random implementation using PHP cryptographically secure functions.
This is the production implementation using actual random sources.
Table of Contents
Interfaces
- IRandom
- Interface for random generation abstraction.
Methods
- bytes() : string
- Generate cryptographically secure random bytes
- float() : float
- Generate random float between 0 and 1
- int() : int
- Generate random integer in range (inclusive)
- shuffle() : array<string|int, mixed>
- Shuffle an array randomly
- string() : string
- Generate random string using specified charset
- uniqueId() : string
- Generate unique identifier
- stringFromCharset() : string
- Generate random string from character set
Methods
bytes()
Generate cryptographically secure random bytes
public
bytes(int $length) : string
Parameters
- $length : int
-
Number of bytes to generate
Tags
Return values
string —Random bytes
float()
Generate random float between 0 and 1
public
float() : float
Tags
Return values
float —Random float between 0.0 and 1.0
int()
Generate random integer in range (inclusive)
public
int(int $min, int $max) : int
Parameters
- $min : int
-
Minimum value (inclusive)
- $max : int
-
Maximum value (inclusive)
Tags
Return values
int —Random integer
shuffle()
Shuffle an array randomly
public
shuffle(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
-
Array to shuffle
Tags
Return values
array<string|int, mixed> —Shuffled array
string()
Generate random string using specified charset
public
string(int $length[, string $charset = 'hex' ]) : string
Parameters
- $length : int
-
Length of the string
- $charset : string = 'hex'
-
Character set ('hex', 'base64', 'alphanumeric', 'alpha', 'numeric')
Tags
Return values
string —Random string
uniqueId()
Generate unique identifier
public
uniqueId([string $prefix = '' ]) : string
Parameters
- $prefix : string = ''
-
Prefix for the unique ID
Tags
Return values
string —Unique identifier
stringFromCharset()
Generate random string from character set
private
stringFromCharset(int $length, string $chars) : string
Parameters
- $length : int
-
Length of string
- $chars : string
-
Available characters
Return values
string —Random string