title: rand() not so random in perl
body: <p>I have a Perl script that gives me a 50 character string of random numbers, letters and some special characters.  I am inputting them in a database.  Now, given the length of the string and the amount of characters, I wouldn't think that duplicates would be easily created.</p>
  
  <p>Here's the nifty nugget of code that creates the string:</p>
  
  <pre><code>my $random_id='';
  my @c = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ &amp; *) );
  $random_id = join '', map $c[rand @c] , 1 .. 50;
  </code></pre>
  
  <p>It produces strings like:</p>
  
  <blockquote>
    <p>C1Qt8L7E7QUD%lkxnh9yjZ2njF0iMj!1o^4DmTbVNhQB9%dke@</p>
  </blockquote>
  
  <p>The problem is it will duplicate an exact string every once and a while among unique ones, and more than once on some strings.  And this is out of say 20 strings.  It's bizarre.  I can work around it and find a solution... but this perplexes me a bit.  Would like to know why.  Anybody have an idea?</p>