<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Creating 50,000 unique values</title>
	<atom:link href="http://jeremycook.ca/2010/07/11/creating-50000-unique-values/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeremycook.ca/2010/07/11/creating-50000-unique-values/</link>
	<description>Random musings on web development and PHP</description>
	<lastBuildDate>Fri, 03 Feb 2012 22:22:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Jeremy Cook</title>
		<link>http://jeremycook.ca/2010/07/11/creating-50000-unique-values/comment-page-1/#comment-333</link>
		<dc:creator>Jeremy Cook</dc:creator>
		<pubDate>Mon, 12 Jul 2010 14:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=135#comment-333</guid>
		<description>Thanks Keith, that one is faster than &#039;Hamlet&#039; but it didn&#039;t work for me under Apache on Windows. If my theory is correct the problem is the use of str_shuffle(), which generated huge numbers of duplicates for me after just 4 iterations.</description>
		<content:encoded><![CDATA[<p>Thanks Keith, that one is faster than &#8216;Hamlet&#8217; but it didn&#8217;t work for me under Apache on Windows. If my theory is correct the problem is the use of str_shuffle(), which generated huge numbers of duplicates for me after just 4 iterations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Evetts</title>
		<link>http://jeremycook.ca/2010/07/11/creating-50000-unique-values/comment-page-1/#comment-332</link>
		<dc:creator>Keith Evetts</dc:creator>
		<pubDate>Mon, 12 Jul 2010 09:19:41 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=135#comment-332</guid>
		<description>I should add that on Apache, the following method is fifty times quicker than encrypting Hamlet (you need to write an Exception class to go with it):

function get_codes( $numcodes, $codelength , $wastage = 25 ) { 
     if ( is_int($numcodes) 
          &amp;&amp; is_int($codelength) 
          &amp;&amp; $codelength &gt;= 5 
          &amp;&amp; $codelength &lt;= 40 
          &amp;&amp; is_int($wastage) ) 
     {
	    
   // acceptable characters
   $goodchars = &#039;2346789AaBbDdEeFfHhJjKkMmNnPpRrTtWwXxYyZz&#039;;
   // build array allowing for possible wastage through duplicate values
   do { $unique_array[] = substr ( str_shuffle( $goodchars ) , 0 , $codelength );
        } while ( sizeof ( $unique_array )  $numcodes + 1 ) {
	      return array_slice ( $unique_array, 0, ($numcodes + 1) );
	 } else throw new CodeGenException ( $numcodes - $size.&#039; fewer codes produced than requested: wastage&#039;, 1, $numcodes, $codelength );
	} else throw new CodeGenException ( &#039;function get_codes called with wrong params&#039;, 2, $numcodes, $codelength );
} // end func
___________________________
Notes: 
- the string $goodchars comprises alphanumeric characters optimised to reduce visual confusions
- $goodchars must be longer than max codelength.  Currently 41 chars.
- $wastage is tuned for default of 25 for a 5-character code
- average time to execute for an array of 50000 codes of 8-character length is 0.25 seconds
- you can try...catch CodeGenException # 1 and try the function again with a greater allowance for wastage</description>
		<content:encoded><![CDATA[<p>I should add that on Apache, the following method is fifty times quicker than encrypting Hamlet (you need to write an Exception class to go with it):</p>
<p>function get_codes( $numcodes, $codelength , $wastage = 25 ) {<br />
     if ( is_int($numcodes)<br />
          &amp;&amp; is_int($codelength)<br />
          &amp;&amp; $codelength &gt;= 5<br />
          &amp;&amp; $codelength &lt;= 40<br />
          &amp;&amp; is_int($wastage) )<br />
     {</p>
<p>   // acceptable characters<br />
   $goodchars = &#039;2346789AaBbDdEeFfHhJjKkMmNnPpRrTtWwXxYyZz&#039;;<br />
   // build array allowing for possible wastage through duplicate values<br />
   do { $unique_array[] = substr ( str_shuffle( $goodchars ) , 0 , $codelength );<br />
        } while ( sizeof ( $unique_array )  $numcodes + 1 ) {<br />
	      return array_slice ( $unique_array, 0, ($numcodes + 1) );<br />
	 } else throw new CodeGenException ( $numcodes &#8211; $size.&#8217; fewer codes produced than requested: wastage&#8217;, 1, $numcodes, $codelength );<br />
	} else throw new CodeGenException ( &#8216;function get_codes called with wrong params&#8217;, 2, $numcodes, $codelength );<br />
} // end func<br />
___________________________<br />
Notes:<br />
- the string $goodchars comprises alphanumeric characters optimised to reduce visual confusions<br />
- $goodchars must be longer than max codelength.  Currently 41 chars.<br />
- $wastage is tuned for default of 25 for a 5-character code<br />
- average time to execute for an array of 50000 codes of 8-character length is 0.25 seconds<br />
- you can try&#8230;catch CodeGenException # 1 and try the function again with a greater allowance for wastage</p>
]]></content:encoded>
	</item>
</channel>
</rss>

