Neuron-PHP

IRandom

Interface for random generation abstraction.

Provides a testable abstraction over random operations. Implementations can be cryptographically secure for production or predictable for testing.

Table of Contents

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

Methods

bytes()

Generate cryptographically secure random bytes

public bytes(int $length) : string
Parameters
$length : int

Number of bytes to generate

Tags
throws
Exception

If random source is not available

Return values
string

Random bytes

float()

Generate random float between 0 and 1

public float() : float
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)

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

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')

Return values
string

Random string

uniqueId()

Generate unique identifier

public uniqueId([string $prefix = '' ]) : string
Parameters
$prefix : string = ''

Prefix for the unique ID

Return values
string

Unique identifier


        
On this page

Search results