Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2. //To Pull 7 Unique Random Values Out Of AlphaNumeric
  3.  
  4. //removed number 0, capital o, number 1 and small L
  5. //Total: keys = 32, elements = 33
  6. $characters = array(
  7. "A","B","C","D","E","F","G","H","J","K","L","M",
  8. "N","P","Q","R","S","T","U","V","W","X","Y","Z",
  9. "1","2","3","4","5","6","7","8","9");
  10.  
  11. //make an "empty container" or array for our keys
  12. $keys = array();
  13.  
  14. //first count of $keys is empty so "1", remaining count is 1-6 = total 7 times
  15. while(count($keys) < 7) {
  16. //"0" because we use this to FIND ARRAY KEYS which has a 0 value
  17. //"-1" because were only concerned of number of keys which is 32 not 33
  18. //count($characters) = 33
  19. $x = mt_rand(0, count($characters)-1);
  20. if(!in_array($x, $keys)) {
  21. $keys[] = $x;
  22. }
  23. }
  24.  
  25. foreach($keys as $key){
  26. $random_chars .= $characters[$key];
  27. }
  28.  
  29. echo 'hasan';
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement