title: Selecting a random key from a hash
body: <p>How do you select a random hash key? For <a href="http://apps.facebook.com/video-preferans/" rel="nofollow noreferrer">my Flash+Perl card game</a> I'm trying to pick a random card from a hash where keys are: "6 spades", "6 clubs", etc. like this:</p>
  
  <pre><code>my $card;
  my $i = 0;
  for $card (keys %{$user-&gt;{HAND}}) {
      last if rand(++$i) &lt; 1;
  }
  delete $user-&gt;{HAND}-&gt;{$card};
  print "random card: $card\n";
  </code></pre>
  
  <p>I wonder if it's the correct way or if there is a better way.</p>