Phrase (Text) Random

I want a text to connect to a dataset and randomly extract a text.

Example:

  1. I enter the ‘new page’.
  2. The random text of the dataset is loaded.
  3. Done! (If I go back into the tab, another text appears, NOT the same one).

All the tutorials I have seen so far have not been able to help me more. Is there any function or code that can take the mapped data in the database and randomize which input is selected?

Thanks in advance!

One way to do it:

Step 1. Query the database for all the items (preferably on the backend)

Step 2. Generate a random number which should be less than the actual array length

wixData.query('database_id').limit(1000).find().then( (res) => {
    let items = res.items;
    let randomNum = Math.floor(Math.random() * items.length) - 1;
    let randomItem = items[randomNum];
        console.log(randomItem); //this will be your random database item
 	$w("myText").text = randomItem.value //Set your value on the text element
});

Where do I put this code that you send me in the second option?

In the page code panel