php-utils

Random extends Base
in package

The Random class provides various randomization functions.

Table of Contents

Properties

$author  : mixed
$debug_log  : mixed
$debugger  : mixed
$name  : mixed
$url  : mixed
$vars  : mixed
$verbose  : mixed
$version  : mixed

Methods

__construct()  : mixed
array_pick_random()  : mixed
Picks a random element from an array.
genStr()  : string
Generates a random string.
percentage()  : bool
Determines if a random event occurs based on a given chance.
roll()  : int
Rolls a random number between the specified range.

Properties

$author

public mixed $author = "Darknetzz"

$debug_log

public mixed $debug_log = []

$debugger

public mixed $debugger

$name

public mixed $name = "PHPUtils"

$url

public mixed $url = "https://github.com/Darknetzz"

$vars

public mixed $vars

$verbose

public mixed $verbose = \true

$version

public mixed $version = "1.0.0"

Methods

__construct()

public __construct() : mixed

array_pick_random()

Picks a random element from an array.

public array_pick_random(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

The array to pick a random element from.

Return values
mixed

The randomly picked element.

genStr()

Generates a random string.

public genStr([int $len = 24 ][, array<string|int, mixed> $charset = [] ][, array<string|int, mixed> $required = [] ]) : string
Parameters
$len : int = 24

The length of the generated string. Default is 24.

$charset : array<string|int, mixed> = []

The character set to use for generating the string. Default is an empty array.

$required : array<string|int, mixed> = []

The types of characters that must be included in the generated string. Default is an empty array.

Return values
string

The generated random string.

percentage()

Determines if a random event occurs based on a given chance.

public percentage([int $chance = 50 ]) : bool
Parameters
$chance : int = 50

The chance of the event occurring, in percentage. Default is 50.

Return values
bool

True if the event occurs, false otherwise.

roll()

Rolls a random number between the specified range.

public roll([int $from = 1 ][, int $to = 100 ]) : int
Parameters
$from : int = 1

The minimum value of the range. Default is 1.

$to : int = 100

The maximum value of the range. Default is 100.

Return values
int

The randomly rolled number.


        
On this page

Search results