Random background images and video on load

Hello,
I need random images/videos to load whenever I refresh the page.
Currently I have this code but it is for only images
import wixWindow from ‘wix-window’ ;
import wixData from ‘wix-data’ ;

$w . onReady ( async function () {

if ( wixWindow . rendering . env === ‘browser’ || wixWindow . viewMode === ‘Preview’ ) {
let res = await wixData . query ( “RandomHomePageImagesVideos” ). find ();
let items = res . items ;
let count = items . length ;
let rnd = Math . floor ( Math . random () * count );
$w ( ‘Document’ ). background . src = items [ rnd ]. image ;
}
});
But there is one more problem, this code works and background also starts to show random but if I open other pages then this random appears on other pages as well and disappear when I refresh it and it turns into a white page. I want the other pages to not sync the code.
The thing is I want a white page, if I open another page then that page should be white. The code should not affect the other pages, the other pages need to remain white by default.
Code should work on the one page on which I have applied on