Random split

Splits an array into random length parts.

Snippet information

Author:
Jonas John

License:
Public Domain

Language:
PHP

Created:
05/17/2006

Updated:
05/17/2006

Tags:
,


function RandomSplit($min, $max, $str){
    $a = array();
 
    while ($str != ''){
        $p = rand($min, $max);
        $p = ($p > strlen($str)) ? strlen($str) : $p;
 
        $buffer = substr($str, 0, $p);
        $str = substr($str, $p, strlen($str)-$p);
 
        $a[] = $buffer;
    }
    return $a;
}


Found a bug? Or do you have a better solution for this?
Feel free to leave a message:

Add a comment


Leave a comment