Randomized Repeater Module

Hello,

Can someone help me get some code for creating a randomized repeater that will only show ONE random professional from my professional database? I have gone through multiple codes given out on here, and they either aren’t working, or will repeat out ALL professionals in my database randomly. I want only one to show, and for it to update randomly every time the page is re-loaded.

Here is the code i’m using that successfully randomizes the professionals, but I need it to only show one at a time:

import wixData from ‘wix-data’;
$w.onReady( function () {
//get the collection records
wixData.query(“Professionals”)
.find()
.then((result) => {
const shuffledArray = shuffleArray(result.items);
//add the shuffled array data to then repeaters
$w(‘#meetTheTeamBox’).data = shuffledArray;
})
. catch ((err) => {
let errorMsg = err;
});
});
//random array index
function getRandomIndex(min, max) {
return Math.round(Math.random() * (max - min) + min);
}
//shuffle array data
function shuffleArray(dataArray){
for(let i = dataArray.length - 1; i > 0; i–){
let index = getRandomIndex(0, i);
const temp = dataArray[i];
dataArray[i] = dataArray[index];
dataArray[index] = temp;
}

return dataArray;
}

Thanks in advance!

Instead of:

$w('#meetTheTeamBox').data = shuffledArray;

Could you try:
$w(‘#meetTheTeamBox’).data = shuffledArray[0];

That worked in the sense that now it’s only showing one item, but now it’s not randomized. It always shows the same item even when the page is refreshed.
I have the repeater (#meetTheTeamBox) connected to data – do I need to disconnect and add code to connect that data instead? I couldn’t figure out what code to add that properly connected the data.

Here is a copy of the page, the “meet the team” box is what i’m referring to: https://kathaynes014.wixsite.com/delta-cgi/copy-of-about

Here is an update:
I found this code which simplifies it a little bit:

export function meetTheTeamBox_itemReady($item, itemData, index) {
$w("#dataset1").setFilter(wixData.filter());
let count = $w("#dataset1").getTotalCount();
let idx = Math.floor(Math.random() * count);
$w("#dataset1").setCurrentItemIndex(idx);}

The only thing with this code, is that it’s cycling through all the people while on the page instead of just picking one and changing once the page is refreshed (please see here: https://kathaynes014.wixsite.com/delta-cgi/about)

Can anyone help me with code to keep the one item on the page until it is refreshed?