class Algorithms (View source)

A utility class for various algorithms.

Methods

static string
generateUUID()

Generates a universally unique identifier (UUID) according to RFC 4122.

static string
generateRandomBytes(int $count)

Returns a string of random bytes.

static string
generateRandomToken(int $count)

Returns a random token in hex format.

static string
generateRandomString(int $count, string $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')

Returns a random string with alpha-numeric characters.

Details

static string generateUUID()

Generates a universally unique identifier (UUID) according to RFC 4122.

The algorithm used here, might not be completely random.

If php-uuid was installed it will be used instead to speed up the process.

Optionally generate type 1 and type 5 UUIDs.

Return Value

string

The universally unique id

Exceptions

Exception

static string generateRandomBytes(int $count)

Returns a string of random bytes.

Parameters

int $count

Number of bytes to generate

Return Value

string

Random bytes

Exceptions

Exception

static string generateRandomToken(int $count)

Returns a random token in hex format.

Parameters

int $count

Token length

Return Value

string

A random token

Exceptions

Exception

static string generateRandomString(int $count, string $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')

Returns a random string with alpha-numeric characters.

Parameters

int $count

Number of characters to generate

string $characters

Allowed characters, defaults to alpha-numeric (a-zA-Z0-9)

Return Value

string

A random string

Exceptions

Exception