<?php
/*
Plugin Name: Random Keywords
Plugin URI: http://yourls.org/
Description: Assign random keywords to shorturls, like bitly (sho.rt/hJudjK)
Version: 1.1
Author: Ozh
Author URI: http://ozh.org/
*/

/* Release History:
*
* 1.0 Initial release
* 1.1 Added: don't increment sequential keyword counter & save one SQL query
* Fixed: plugin now complies to character set defined in config.php
*/

global $ozh_random_keyword;

/*
* CONFIG: EDIT THIS
*/

/* Length of random keyword */
$ozh_random_keyword['length'] = 5;

/*
* DO NOT EDIT FARTHER
*/

// Generate a random keyword
yourls_add_filter( 'random_keyword', 'ozh_random_keyword' );
function ozh_random_keyword() {
        global $ozh_random_keyword;
        $possible = yourls_get_shorturl_charset() ;
        $str='';
        while (strlen($str) < $ozh_random_keyword['length']) {
                $str .= substr($possible, rand(0,strlen($possible)-1),1);
        }
        return $str;
}

// Don't increment sequential keyword tracker
yourls_add_filter( 'get_next_decimal', 'ozh_random_keyword_next_decimal' );
function ozh_random_keyword_next_decimal( $next ) {
        return ( $next - 1 );
}

<?php
/*
Plugin Name: Random Keywords
Plugin URI: http://yourls.org/
Description: Assign random keywords to shorturls, like bitly (sho.rt/hJudjK)
Version: 1.1
Author: Ozh
Author URI: http://ozh.org/
*/

/* Release History:
*
* 1.0 Initial release
* 1.1 Added: don't increment sequential keyword counter & save one SQL query
* Fixed: plugin now complies to character set defined in config.php
*/

global $ozh_random_keyword;

/*
* CONFIG: EDIT THIS
*/

/* Length of random keyword */
$ozh_random_keyword['length'] = 5;

/*
* DO NOT EDIT FARTHER
*/

// Generate a random keyword
yourls_add_filter( 'random_keyword', 'ozh_random_keyword' );
function ozh_random_keyword() {
        global $ozh_random_keyword;
        $possible = yourls_get_shorturl_charset() ;
        $str='';
        while (strlen($str) < $ozh_random_keyword['length']) {
                $str .= substr($possible, rand(0,strlen($possible)),1);
        }
        return $str;
}

// Don't increment sequential keyword tracker
yourls_add_filter( 'get_next_decimal', 'ozh_random_keyword_next_decimal' );
function ozh_random_keyword_next_decimal( $next ) {
        return ( $next - 1 );
}

--- 
+++ 
@@ -35,7 +35,7 @@
         $possible = yourls_get_shorturl_charset() ;
         $str='';
         while (strlen($str) < $ozh_random_keyword['length']) {
-                $str .= substr($possible, rand(0,strlen($possible)),1);
+                $str .= substr($possible, rand(0,strlen($possible)-1),1);
         }
         return $str;
 }
Fix getting random character from charset

If strlen($possible) is for example 36, rand could also return 36. But substr starts with position 0. So we have to subtract 1 from strlen($possible).