title: How to generate a random string in Ruby
body: <p>I'm currently generating an 8-character pseudo-random uppercase string for "A" .. "Z":</p>
  
  <pre><code>value = ""; 8.times{value  &lt;&lt; (65 + rand(25)).chr}
  </code></pre>
  
  <p>but it doesn't look clean, and it can't be passed as an argument since it isn't a single statement.  To get a mixed-case string "a" .. "z" plus "A" .. "Z", I changed it to:</p>
  
  <pre><code>value = ""; 8.times{value &lt;&lt; ((rand(2)==1?65:97) + rand(25)).chr}
  </code></pre>
  
  <p>but it looks like trash.</p>
  
  <p>Does anyone have a better method?</p>