Jump to content

Recommended Posts

Not blowing my own but I dont think so...

 

here is the code I'm trying to generate the 250000 unique strings...

 

<?php
$chars		= "ABCDEFGHJKLMNPQRSTUVWXYZ";
$charend	= (strlen ( $chars ) - 1);

$date		= date ( 'md' );

$month = $date[0].$date[1];
$year = $date[2].$date[3];

$datecode	=	$chars[$month] . $chars[$year[0]] . $chars[$year[1]];
$uniquecodes	=	array();
$no_codes	=	isset( $_GET['no_codes'] ) ? $_GET['no_codes'] : 250000;

$codecount	=	0;

do
{
$codes		=	array();
for ( $j = $codecount ; $j < $no_codes ; $j++ )
{
	$trackcode = NULL;
	for ( $i = 0 ; $i < 7 ; $i++ )
	{
		$x = rand( 0 , $charend );
		$trackcode	.= $chars[rand( 0 , $charend )];
	}
	$codes[]	=	$trackcode . $datecode;
}
$unique		=	array_merge ( $codes , $uniquecodes );
$uniquecodes	=	array_unique ( $unique );
$codecount	=	count ( $uniquecodes );

if	(
	(time() - $start) > 60
	)
{
	break; // just in to break out of infite loop in dev.
}

} while ( $codecount < ($no_codes) - 1 );
echo 'Unique Codes: ' . $codecount . PHP_EOL;
?>

the date portion (last three characters) is used to keep keys separated by date - these are to be added to a database and i can check if any existing codes end in the same three characters (if they do then I'll manage that elsewhere).

so essentially a 7 letter random string shouold yield 24^7 combos (I omitt I and O so as not to confuse with numbers) which works out at 4,500,000,000 so there should be plenty of room for manouvre.

Could this be a memory limit issue or am I missing something much more fundamental?

Cheers peeps.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.