Randomise Repeater Simply?

Hi,

I am using the following to randomise a dataset on both page load and click of a button; however, it doesn’t seem to work.

I simply have a list of videos in a dataset and want a single random item to appear in the video player when the user first loads the page and when they click the button on the page

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
export function pageload(event) {
// clear any filters in the dataset
$w(“#dataset1”).setFilter(wixData.filter());
// get size of collection that is connected to the dataset
let count = $w(“#dataset1”).getTotalCount();
// get random number using the size as the maximum
let idx = Math.floor(Math.random() * count);
// set the current item index of the dataset
$w(“#dataset1”).setCurrentItemIndex(idx);
}

Any advice appreciated!

import wixData from 'wix-data';
$w.onReady(() => {
 $w("#dataset1").onReady(() => {
  let count = $w("#dataset1").getTotalCount();
  $w("#dataset1").getItems(Math.floor(Math.random() * count), 1)
  .then(r => {
   let selectedItem = r.items[0];
   $w("#videoPlayer1").src = selectedItem.video;//use your collection field key  instead of "video";
  })
 })
})