Crypt::randomBytes

public static Crypt::randomBytes($count)

Returns a string of highly randomized bytes (over the full 8-bit range).

This function is better than simply calling mt_rand() or any other built-in PHP function because it can return a long string of bytes (compared to < 4 bytes normally from mt_rand()) and uses the best available pseudo-random source.

In PHP 7 and up, this uses the built-in PHP function random_bytes(). In older PHP versions, this uses the random_bytes() function provided by the random_compat library.

Parameters

int $count: The number of characters (bytes) to return in the string.

Return value

string A randomly generated string.

File

core/lib/Drupal/Component/Utility/Crypt.php, line 30

Class

Crypt
Utility class for cryptographically-secure string handling routines.

Namespace

Drupal\Component\Utility

Code

public static function randomBytes($count) {
  return random_bytes($count);
}
doc_Drupal
2016-10-29 08:59:10
Comments
Leave a Comment

Please login to continue.