class Rand (View source)

Class for generating random numbers

Methods

static string
generate(int $num, bool $must_be_strong = true, bool $returned_strong_result = true)

Generates pseudo random bytes

static null
seed(string $buf, float $entropy)

Mixes bytes in $buf into PRNG state

static null
cleanup()

Cleans up PRNG state

static int
loadFile(string $filename, int $max_bytes = -1)

Reads a number of bytes from file $filename and adds them to the PRNG. If max_bytes is non-negative, up to to max_bytes are read; if $max_bytes is negative, the complete file is read

static int
writeFile(string $filename)

Writes a number of random bytes (currently 1024) to file $filename which can be used to initializethe PRNG by calling Crypto\Rand::loadFile() in a later session

Details

static string generate(int $num, bool $must_be_strong = true, bool $returned_strong_result = true)

Generates pseudo random bytes

Parameters

int $num
bool $must_be_strong
bool $returned_strong_result

Return Value

string

static null seed(string $buf, float $entropy)

Mixes bytes in $buf into PRNG state

Parameters

string $buf
float $entropy

[optional] The default value is (float) strlen($buf)

Return Value

null

static null cleanup()

Cleans up PRNG state

Return Value

null

static int loadFile(string $filename, int $max_bytes = -1)

Reads a number of bytes from file $filename and adds them to the PRNG. If max_bytes is non-negative, up to to max_bytes are read; if $max_bytes is negative, the complete file is read

Parameters

string $filename
int $max_bytes

Return Value

int

static int writeFile(string $filename)

Writes a number of random bytes (currently 1024) to file $filename which can be used to initializethe PRNG by calling Crypto\Rand::loadFile() in a later session

Parameters

string $filename

Return Value

int