random string

    0

    2

    jvitrandom
    JVIT PHP

    The code generates a random string of 16 bytes.

    Shortcut: str.random

    /**
    * Generate random string
    * @param int $length
    * @return string
    */
    function generateRandomString($length = 16)
    {
      // PHP 7
      if (function_exists('random_bytes')) {
        $bytes = random_bytes($length / 2);
      } else {
        $bytes = openssl_random_pseudo_bytes($length / 2);
      }
      return bin2hex($bytes);
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.