<?php 
function randstr($len=4) {
    $abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $letters = str_split($abc);
    $str = "";
    for ($i=0; $i<=$len; $i++) {
        $str .= $letters[rand(0, count($letters)-1)];
    };
    return $str;
}

$limit=4;
$license="";
for ($i=1; $i<=$limit; $i++) {
    $new=randstr(4);
    $license .= $new.'-';
}

echo rtrim($license, "-");
?>
Ben bunu kullanıyorum