National Insurance number generator I am trying to figure out how to DRY up this code:

nino = "QQ"
3.times { nino += Random.rand(10..99).to_s}
nino += ("A".."D").to_a.sample


I am trying to generate a sample National Insurance number starting with QQ, six digits and then ending with A, B, C or D.
Why do you need the 3 times? Is there a restriction, that the first number may not be 0? 

If there  is no 0-restriction, you may generate a number between 0 and 999999.
To get the leading 0 I use the strftime-pattern %06i (6 digit with leading zeros).

  p "QQ%06i%s" % [ Random.rand(999999), ("A".."D").to_a.sample ]


For the letter, you may generate a random number from 65..68 and take the character for the selected ASCII-value (code example is ruby 1.9. Maybe you need a little variation with Ruby 1.8):

  p "QQ%06i%s" % [ Random.rand(999999), (65 + rand(4)).chr ]