Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
it's better then
function generate(str) {
return str.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0;
return (c == 'x' ? r : (r & 0x3 | 0x8 )).toString(16);
});
}
generate('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx');
// "03bcf8e8-92de-4afd-9575-955d6ea94f70"
js code dug up like this:
generateUUID = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( /[xy]/g, function ( c ) {
var r = Math.random() * 16 | 0;
return ( c == 'x' ? r : ( r & 0x3 | 0x8 ) ).toString( 16 );
} );
};
protected function generateUId()
{
$idMask = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$result = '';
for ($i = 0; $i < strlen($idMask); $i++) {
if ($idMask[$i] == 'x') {
$result .= $characters[mt_rand(0, 34)];
} else {
$result .= "-";
}
}
return $result;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question