Skip to content

Instantly share code, notes, and snippets.

@jatubio
Forked from sepehr/readable_random_string.php
Created March 3, 2017 00:28
Show Gist options
  • Select an option

  • Save jatubio/deac1a7f485d46350aae9f1650c3d440 to your computer and use it in GitHub Desktop.

Select an option

Save jatubio/deac1a7f485d46350aae9f1650c3d440 to your computer and use it in GitHub Desktop.

Revisions

  1. jatubio revised this gist Mar 3, 2017. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions readable_random_string.php
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,6 @@ function readable_random_string($length = 6)
    'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'
    );

    // Seed it
    srand((double) microtime() * 1000000);

    $max = $length/2;
    for ($i = 1; $i <= $max; $i++)
    {
  2. @sepehr sepehr created this gist Aug 16, 2012.
    30 changes: 30 additions & 0 deletions readable_random_string.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php

    /**
    * Generates human-readable string.
    *
    * @param string $length Desired length of random string.
    *
    * retuen string Random string.
    */
    function readable_random_string($length = 6)
    {
    $string = '';
    $vowels = array("a","e","i","o","u");
    $consonants = array(
    'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm',
    'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'
    );

    // Seed it
    srand((double) microtime() * 1000000);

    $max = $length/2;
    for ($i = 1; $i <= $max; $i++)
    {
    $string .= $consonants[rand(0,19)];
    $string .= $vowels[rand(0,4)];
    }

    return $string;
    }