Advertisement
Guest User

Untitled

a guest
May 1st, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // The characters we want in the output
  2. $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  3. $count = strlen($chars);
  4.  
  5. // Generate 12 random bytes
  6. $bytes = random_bytes(12);
  7.  
  8. // Construct the output string
  9. $result = '';
  10. // Split the string of random bytes into individual characters
  11. foreach (str_split($bytes) as $byte) {
  12. // ord($byte) converts the character into an integer between 0 and 255
  13. // ord($byte) % $count wrap it around $chars
  14. $result .= $chars[ord($byte) % $count];
  15. }
  16.  
  17. // That's all, folks!
  18. echo($result."n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement