bfrohs / random
Cryptographically secure random data generation.
1.1.0
2016-02-29 21:30 UTC
Requires
- php: >=5.2.0
- paragonie/random_compat: ^1.2
This package is not auto-updated.
Last update: 2024-12-07 21:16:04 UTC
README
Cryptographically secure random data generation.
Usage
Hex string
Random string of hexadecimal characters ([0-9a-f]
).
use bfrohs\Random\Random; $string = Random::generateHex(32); var_dump($string);
string(32) "112321ec33df8ebc9234ac02dbae4277"
Url-safe string
Random string that is safe for use in URLs (unreserved characters)
per RFC 3986 ยง 2.3
([a-zA-Z0-9]
, _
, ~
, -
, and .
).
use bfrohs\Random\Random; $string = Random::generateUrlSafeString(32); var_dump($string);
string(32) "XQ_7J495ZWd3s~5TWz-FNFiPkeM3z9K."
Binary
Random bytes.
use bfrohs\Random\Random; $string = Random::generateBinary(32); // Note the use of `bin2hex()` to make output readable var_dump(bin2hex($string));
string(64) "68a74f84be34c9be12ecada360e91639fd0d41cfae368d90fe8cc4c4ff66eed3"
Integer
Random integer.
use bfrohs\Random\Random; $string = Random::generateInt(0, 29524); var_dump($string);
int(12860)