On Dec 7, 7:48 am, Piotr Wlodarek <q... / wp.pl> wrote:
> Peter Hickman wrote:
> > Well there is a Perl module called Data::RandomPerson that generates
> > people records (written by yours truly) which creates gender, age, dob,
> > firstname, lastname and title.
>
> > use Data::RandomPerson;
> > my $r = Data::RandomPerson->new();
>
> That's exactly what I need! But still Ruby-based solution would be
> appreciated.
>
> Jordan Callicoat wrote:
> > What possible *legitimate* need could you have for a million
> > random email addresses and names?
>
> Testing for performance.
> --
> Posted viahttp://www.ruby-forum.com/.

Sorry. It just sounded kind of fishy to ask for a million random email
addresses. If you don't need actual random email addresses, just
random strings that approximate email addresses, it pretty easy. Let's
say an average email address is 10-20 characters, and an average name
is 20-30...

$data = {}
$abc  = ("A".."Z").to_a + ("a".."z").to_a
$host = ["@foo", "@bar", "@baz", "@dolor", "@lorem", "@ipsum"]
$tld  = [".com", ".org", ".net", ".us", ".tl"]

def email
  handle = []
  rand(25).times {
    handle << $abc[rand($abc.length)]
  }
  host = $host[rand($host.length)]
  tld = $tld[rand($tld.length)]
  "%s%s%s" % [handle.join(""), host, tld]
end
def name
  first = []
  rand(15).times {
    first << $abc[rand($abc.length)]
  }
  middle = []
  rand(11).times {
    middle << $abc[rand($abc.length)]
  }
  last = []
  rand(21).times {
    last << $abc[rand($abc.length)]
  }
  "%s %s %s" % [first.join(""),
                middle.join(""),
                last.join("")]
end

csv = File.open("email_name.csv", "w")
1000000.times {
  csv.write("%s,%s\n" % [email, name])
}
csv.close

Takes about 3 minutes to run on my box and generates a ~50 meg CSV
file.

HTH,
Jordan