Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The characters we want in the output
- $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- $count = strlen($chars);
- // Generate 12 random bytes
- $bytes = random_bytes(12);
- // Construct the output string
- $result = '';
- // Split the string of random bytes into individual characters
- foreach (str_split($bytes) as $byte) {
- // ord($byte) converts the character into an integer between 0 and 255
- // ord($byte) % $count wrap it around $chars
- $result .= $chars[ord($byte) % $count];
- }
- // That's all, folks!
- echo($result."n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement