code to get permutations
Posted: Thu Dec 20, 2007 11:21 pm
Code: Select all
$chars = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$chars = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));Using this as a unique identifier for a database row. Incremented numbers are too easily guessable. Not that it's a security issue, but I'd rather someone not view all content by simply incrementing the id in the address bar.onion2k wrote:Isn't that going to be 62^6 different possibilities ... 56,800,235,584 6 character strings ... What on Earth are you doing?
Not if you are just after combinations, but it's still a big number.onion2k wrote:Isn't that going to be 62^6 different possibilities ... 56,800,235,584 6 character strings ... What on Earth are you doing?
Code: Select all
$chars = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
$it = 0;
$strings = array();
while ($it < 3000000)
{
shuffle($chars);
$strings[] = $chars[0] . $chars[1] . $chars[2] . $chars[3] . $chars[4] . $chars[5];
$it++;
}
$strings = array_chunk(array_unique($strings), 300);
foreach ($strings AS $stringChunk)
{
//implode $stringChunk with ',' and insert into database
}