Scriptlog Docs

Scriptlog Documentation

Code reference for the Scriptlog codebase

User Tools

Site Tools


scriptlog:lib:core:random

This is an old revision of the document!


Random

Layer: Core · Source: lib/core/Random.php:17 (lines 17–293)


class Random

Random Class

Docblock Metadata

Inheritance

No parent, interface or trait. This is a root type.

Constants (5)

Visibility Name Value Line
- BLOCK_SIZE 32; 19
- TOKEN_LOWER_ALPHA “abcdefghijklmnopqrstuvwxyz”; 21
- TOKEN_UPPER_ALPHA “ABCDEFGHIJKLMNOPQRSTUVWXYZ”; 22
- TOKEN_ALPHA “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”; 23
- TOKEN_ALNUM “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”; 24

Properties (2)

Visibility Type Name Default Line
private static static $state ''; 26
protected (untyped) $secure false; 28

Methods (12)

Visibility Method Summary Line
public __construct() Construct a new random number generator 35
public bytes() Generate a native binary string 47
public int() Generate a random integer 66
public float() Generate a random floating point number between 0 and 1.0 94
public choose() Given a sequence (string, array or object), pick one of them at random 106
public shuffle() Given a sequence(string, array or object), generate a shuffled sequence 134
public token() Generate a token with the specified alphabet 178
protected genRandom() Protected function to overload the generator for unit testing purposes 201
private genNormal() Generate a non-CS random seed 214
private genSecure() Generate a cryptographically-secure random seed 242
private mergeBuffers() Merge two buffers into a single buffer in a non-deterministic way 273
private countBits() Count the number of bits needed to represent an integer 285

__construct()

public function __construct($secure = false)

lines 35–38 (4)

Construct a new random number generator

Parameter Type Default Description
$secure (untyped) false Should generated random numbers be cryptographically secure

bytes()

public function bytes($length)

lines 47–56 (10)

Generate a native binary string

Parameter Type Default Description
$length (untyped) required The length of the string to generate

Returns: (none declared) — string The generated string

int()

public function int($min, $max = null)

lines 66–87 (22)

Generate a random integer

Parameter Type Default Description
$min (untyped) required The starting point, or if max is omitted the ending point
$max (untyped) null The ending point

Returns: (none declared) — int The generated integer

float()

public function float()

lines 94–97 (4)

Generate a random floating point number between 0 and 1.0

Takes no parameters.

Returns: (none declared) — float The generated float

choose()

public function choose($value)

lines 106–124 (19)

Given a sequence (string, array or object), pick one of them at random

Parameter Type Default Description
$value (untyped) required The sequence to choose from

Returns: (none declared) — mixed The randomly chosen value

shuffle()

public function shuffle($value)

lines 134–168 (35)

Given a sequence(string, array or object), generate a shuffled sequence

Note: for strings, the return is a string. For arrays and objects, it's an array

Parameter Type Default Description
$value (untyped) required The sequence to choose from

Returns: (none declared) — string|array The generated shuffled sequence

token()

public function token($length, $alphabet = self::TOKEN_ALNUM)

lines 178–196 (19)

Generate a token with the specified alphabet

Parameter Type Default Description
$length (untyped) required The length of the token to generate
$alphabet (untyped) self::TOKEN_ALNUM The “alphabet” (characters) to use

Returns: (none declared) — string The generated random token

genRandom()

protected function genRandom()

lines 201–209 (9)

Protected function to overload the generator for unit testing purposes

Takes no parameters.

Returns: (none declared)

genNormal()

private function genNormal()

lines 214–237 (24)

Generate a non-CS random seed

Takes no parameters.

Returns: (none declared)

genSecure()

private function genSecure()

lines 242–268 (27)

Generate a cryptographically-secure random seed

Takes no parameters.

Returns: (none declared)

mergeBuffers()

private function mergeBuffers($buffer1, $buffer2)

lines 273–280 (8)

Merge two buffers into a single buffer in a non-deterministic way

Parameter Type Default Description
$buffer1 (untyped) required none
$buffer2 (untyped) required none

Returns: (none declared)

countBits()

private function countBits($number)

lines 285–292 (8)

Count the number of bits needed to represent an integer

Parameter Type Default Description
$number (untyped) required none

Returns: (none declared)


This page is generated from source by 'tools/gendoc'. Edits will be overwritten.

scriptlog/lib/core/random.1790414217.txt.gz · Last modified: by admin