Quick Question: How many names are there?

68 views
Skip to first unread message

Ruben Martinez Jr.

unread,
Jul 5, 2014, 6:17:18 PM7/5/14
to ruby-...@googlegroups.com
I'm curious to use this (awesome looking!) gem in a project, and I'm just wondering where the name data comes from, or how it gets populated. If I were to use this gem and run a loop to generate names, how often would it repeat?

Thanks! Keep up the great work!

Jesse Cooke

unread,
Jul 6, 2014, 4:25:28 AM7/6/14
to ruby-...@googlegroups.com
The name data comes from the YAML files in lib/locales.

`Faker::Name.name` essentially calls `first_name` and `last_name` (which both rely on `fetch`, which the implementation takes a sample of all the items in the corresponding array) you'll get some random distribution that follows whatever Ruby's `Array#sample` follows. It will repeat.

>> require 'faker'; require 'set'
>> s = Set.new
>> 1_000_000.times { s << Faker::Name.name }
=> 1000000
>> s.size
=> 863401

That's a lot more repetition that I suspected, but you could handle that by yourself.

- Jesse


On Sun, Jul 6, 2014 at 12:17 AM, Ruben Martinez Jr. <ruben.ma...@gmail.com> wrote:
I'm curious to use this (awesome looking!) gem in a project, and I'm just wondering where the name data comes from, or how it gets populated. If I were to use this gem and run a loop to generate names, how often would it repeat?

Thanks! Keep up the great work!

--
You received this message because you are subscribed to the Google Groups "Ruby Faker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-faker+...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-faker.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages