How do I extract a random record from a Softr Database table?

I’m trying to implement this scenario.

  1. I have a softr database with a table containing n records.

  2. I have a page that displays a List-detail.

  3. When I load the page, I need to read the table and filter the contents based on the value in a column.

  4. Of the filtered records, I need to display only one randomly selected record that will be different each time I access the page.

    How can I implement this scenario using softr’s internal database?
    My main problem is how to get a random record from the filtered list.

You could try adding a new formula column to your table and use this as the (pseudo) random second filter:

Time-Based Selection (using current time for pseudo-randomness)

Add a formula field that generates a string based on a combination of current time and recordID.

On page, use block conditions:

  • Sort by this field descending
  • Limit to 1 record

See how that works out, I had success with something similar in Airtable so it should be possible in Softr database too.

1 Like

Thanks. I did as you said.
I created a formula in a field that populates the entire column with random numbers.

This is the formula: RANDBETWEEN(1,1000000) + FLOOR(DATETIME_DIFF(NOW(), DATETIME_FORMAT(NOW(), ‘yyyy-MM-dd HH:00:00’), ‘minute’) / 120)

Then on the web app page, I filter, sort, and choose to show a single record. It works.

The problem is that the random numbers in the column only change when I make changes to softr’s internal database.

So, once I save and close the database, then launch the web app, the random order of the records always remains the same. Thus it shows always the same content.

For example, if I open my web app the next day, it always shows the record with the highest random number.

My requirement is that every time I reload the page, it displays a different random record.

What else can I do to achieve this result?

I had a look at my original use-case for a website I used to be admin for … it was to reorder a small set of (50) records (people!) every 24 hours in a random way.

Your use-case, needing a new random record to be displayed every page refresh, probably needs some JavaScript, alongside a back-end formula.

I can’t help you with JS myself, but would suggest getting an AI model to help you with this.

Hope it all works out as you want it to.

1 Like

I think @MarkSchofield is right here. Only thing I’d add is an automation on the backend that refreshes that randomized content. Softr workflows is coming in the next week, which will allow you to create an automation on a schedule like this. Should do the trick.