How to generate whole positive numbers included in a range

31 views
Skip to first unread message

jyf

unread,
Jul 28, 2016, 5:06:24 PM7/28/16
to Ruby Faker
I would like to generate positive integers greater than 300 and smaller than 12000.
Considering Faker documentation, I still have to understand if the following usage can suit me:

Faker::Number.between(300, 12000)

There is a GitHub example which gives '7' as result if the range is between 1 and 10, and I do not understand if this means that the result is an integer.
I am also wondering if it is possible to combine/chain more methods and use for instance the following format:

Faker::Number.number(3, 5).between(300, 12000)

Conrad Taylor

unread,
Jul 28, 2016, 8:41:38 PM7/28/16
to ruby-...@googlegroups.com
Hi, you should be able to do this by using the Ruby Standard Library:

# generate an array of even numbers > 300 but less than 1200
array = (301..11999).select(&:even?)

# generate an even number > 300 but less than 12000
array.sample

Now, you have enough information generate your own between method.  If you have any questions, please do post here.  Well,  I must go and best of luck to you.



--
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 https://groups.google.com/group/ruby-faker.
For more options, visit https://groups.google.com/d/optout.



--

Think different and code well,

-Conrad

Reply all
Reply to author
Forward
0 new messages