Title: gen_random_string function will never find 36th char
Last modified: August 20, 2016

---

# gen_random_string function will never find 36th char

 *  [Azizur Rahman](https://wordpress.org/support/users/azizur/)
 * (@azizur)
 * [15 years ago](https://wordpress.org/support/topic/gen_random_string-function-will-never-find-36th-char/)
 * strlen($characters) would return 36 but php index starts from 0 and not 1. Which
   means you’d never have $characters[36] which will return a php notice.
 * Here is an updated function:
 *     ```
       private function gen_random_string($len) {
               $length = intval($len);
               $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
               $string = '';
               for ($p = 0; $p < $length; $p++) {
                   $string .= $characters[mt_rand(0, strlen($characters)-1)];
               }
               return $string;
           }
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [bsndev](https://wordpress.org/support/users/bsndev/)
 * (@bsndev)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/gen_random_string-function-will-never-find-36th-char/#post-2125867)
 * thanks! will update the code

Viewing 1 replies (of 1 total)

The topic ‘gen_random_string function will never find 36th char’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ultimate-security-checker.svg)
 * [Ultimate Security Checker](https://wordpress.org/plugins/ultimate-security-checker/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-security-checker/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-security-checker/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-security-checker/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-security-checker/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-security-checker/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [bsndev](https://wordpress.org/support/users/bsndev/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/gen_random_string-function-will-never-find-36th-char/#post-2125867)
 * Status: not resolved