rubyruby-on-rails-3rubygemsfaker

Words length in Faker


How to generate array of words of specific length from Faker gem in rails? For example I would like to make an array of five words, where each word's length is also five.


Solution

  • If you want any 5 characters that can mix digits as well as alphabets, maybe this one could help you as well apart from Aliaksei's solution.

    5.times.map { Faker::Lorem.characters(5) }
    

    What it does is it gives you an array of 5 combinations of 5 random characters, that can include any English alphabet in small from a to z and any digit from 0 to 9.

    You get something like this.

    ["uw1ep", "04lhs", "0c4d9", "31n1j", "mrspp"]