I struggle to randomize the gallery after filtering.

Basically what you need is something like this:
Disconnect the gallery from the dataset on the editor (we will bind it via code only);

 import wixData from 'wix-data';//This line must be at the top of the page code
 
async function bindData(){
const itemsRetrival = await $w('#dataset1').getItems(0,1000);
const items = itemsRetrival.items;
for (let i = items.length - 1; i > 0; i--) {
             const j = Math.floor(Math.random() * (i + 1));
             [items[i], items[j]] = [items[j], items[i]];
         }
//map your data field keys to gallery items keys:
$w('#gallery1').items = items.map(e => ({src: e.image, link: e.link, title: e.title}));
}

$w.onReady(() => {
$w('#dataset1').onReady(bindData);
})

//call the filterData inside onClick handler or whenever you wish:
function filterData(){
	//create the filter as you did, then:
$w("#dataset1").setFilter(wixData.filter().eq('tag2', filter)).then(bindData);
}