Random Alpha numeric generator

Posted by AAA on Stack Overflow See other posts from Stack Overflow or by AAA
Published on 2010-12-22T22:08:38Z Indexed on 2010/12/22 22:54 UTC
Read the original article Hit count: 170

Filed under:
|
|
|
|

Hi,

I want to give our users in the database a unique alpha-numeric id. I am using the code below, will this always generate a unique id? Below is the old and updated version of the code:

New php:

// Generate Guid 
function NewGuid() { 

$s = strtoupper(md5(uniqid("something",true))); $guidText = substr($s,0,8) . '-' . substr($s,8,4) . '-' . substr($s,12,4). '-' . substr($s,16,4). '-' . substr($s,20); return $guidText; } // End Generate Guid

$Guid = NewGuid();
echo $Guid;
echo "<br><br><br>";

Old PHP:

// Generate Guid 
function NewGuid() { 
    $s = strtoupper(md5(uniqid("something",true))); 
    $guidText = 
        substr($s,0,8) . '-' . 
        substr($s,8,4) . '-' . 
        substr($s,12,4). '-' . 
        substr($s,16,4). '-' . 
        substr($s,20); 
    return $guidText;
}
// End Generate Guid 

$Guid = NewGuid();
echo $Guid;
echo "<br><br><br>";

Will this first code guarantee uniqueness?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql