I recently posted this, but I'll pop another copy here.

def allowed_chars
  output = []
  output += ('A'..'Z').to_a
  output += ('0'..'9').to_a
end

def random_text( length )
  output = ""
  allowed = allowed_chars()
  length.times do
    output << allowed[ rand( allowed.length ) ]
  end
  output
end

all done with functionality to easily add/remove chars from your set of allowed.

hope that helps.

j.

On 10/4/05, Winston, Phyllis H <[EMAIL PROTECTED]> wrote:
Alan Richardson has an excel spreadsheet using visual basic macros for
data generation:
http://www.compendiumdev.co.uk/testdata/index.php

-----Original Message-----
From: Chris McMahon [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 03, 2005 6:33 PM
To: wtr-general@rubyforge.org
Subject: [Wtr-general] OT: generate random text?

Hi...

I want to generate some random text for test purposes.  "rand" doesn't
seem to DWIM.  Say, to pick an arbitrary letter from the uppercase
range A to Z.

[A-Z].rand
[A..Z].rand

seems right, but isn't.
-Chris



_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general



--
" http://ruby-lang.org -- do you ruby?"

Jeff Wood
_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to