Generating Fake Data in Elixir

Faker.Lorem.Paragraphs generates paragraphs with random words/sentences. I have a requirement where I am supposed to generate paragraphs with meaningful business related sentences and pass it as a value to a field in my factory. Is there any way I could achieve this in Elixir?

Do you have an example of your requirement to add to the question? I only worked with Faker before, but if you leave an example of what you are searching for perhaps someone else could help.

Sure, this is a piece of content from Robinhood’s articles.

The more varied and diversified your investments are, the better able they are to help you mitigate losses.

There’s no shortage of choice when it comes to where you can invest your money. In addition to stocks and bonds, there are money market funds, real estate, commodities, private equities, and so on. What’s more, within each investment class, you can put your money in different companies, industry sectors, geographies, and currencies.

With a diversified portfolio, the idea is that the more varied your collection of asset classes and funds, the better it can mitigate losses. Markets tend to work in cycles, and different markets may go up or down at different times. In theory, a diversified portfolio can help your investments so if a few markets take a hit one year, other parts of your portfolio might continue to grow.

So what kind of mix is right for you?

The answer depends on who you are and what you are trying to achieve with your investments. You might decide to invest more money in one class or sector over another based on your financial needs, personality, and timeline.

I look forward to generating data like these paragraphs.

Is this for test only or do you need to generate those paragraphs for something else?

If it’s for test-only I’m not sure generating random paragraphs based on another predetermined content is going to do much better than using Lorem Ipsums. At least I can’t see the benefit of testing with one over the other. Unless of course, you have a very specific business use case you want to test.

If this is for something else perhaps you could take a look at the Faker implementation and generate a custom rule that satisfies your needs.

Also, if by “meaningful business-related sentences” you mean based on actual existing text, from books, articles, and so on; I’d guess this is too specific.

A very naive implementation could look like this:

words = ~w"""
The more varied and diversified your investments are, the better able they are to help you mitigate losses.

There’s no shortage of choice when it comes to where you can invest your money. In addition to stocks and bonds, there are money market funds, real estate, commodities, private equities, and so on. What’s more, within each investment class, you can put your money in different companies, industry sectors, geographies, and currencies.

With a diversified portfolio, the idea is that the more varied your collection of asset classes and funds, the better it can mitigate losses. Markets tend to work in cycles, and different markets may go up or down at different times. In theory, a diversified portfolio can help your investments so if a few markets take a hit one year, other parts of your portfolio might continue to grow.

So what kind of mix is right for you?

The answer depends on who you are and what you are trying to achieve with your investments. You might decide to invest more money in one class or sector over another based on your financial needs, personality, and timeline.
"""

Enum.take_random(words, 10)

If this needs to make sense in a sentence, you could also split by paragraphs instead of words.
But perhaps this is too naive for you, in that case you should look for another solution.