Generate random sentences
Question

Hi guys,

Im developing an app where everytime i log in i want to show a random sentence.

I've already created a table called Quote, but in terms of logic i don't know how to develop from this point.

Can you help me please.


Diogo.

Hi all, since the quote table should be smaller, you can also use a query to do that.

https://afana.me/archive/2010/12/01/random-rows-efficiently-in-sql-server.aspx/

EG: select  top(1) * from Orders order by newid() 

mvp_badge
MVP

Hello Diogo,

Will your Entity contain the entire sentence? Assuming that you're not trying to combinate fragments to generate sentences, all you need at this point is some form of randomness.

You can use this Forge component to generate a random number between an interval. So assuming that your Entity has a continuous ID (1,2,3,4, etc and not 1,2,5,8), you can get the smallest and the largest ID of your Entity, use them as inputs to this Forge component, and obtain a random number. This random number would be the ID of the record you would then fetch from your Entity.

Hi all, since the quote table should be smaller, you can also use a query to do that.

https://afana.me/archive/2010/12/01/random-rows-efficiently-in-sql-server.aspx/

EG: select  top(1) * from Orders order by newid() 

mvp_badge
MVP


Hey Diogo,

I've gone ahead and marked Luis' answer as the solution - I think it's more elegant than obtaining an ID before calling the database, as long as your Quote Entity is kept small.

Let us know if you managed to solve this, or if you need any assistance.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.