Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Shuffling cards in a repeater using images from a dataset in Wix

I am creating a page on Wix where I have a repeater that only brings 3 items from my dataset at a time when clicking on the shuffling button (there are 22 cards in the dataset) that is supposed to shuffle and bring different combinations.

What I expect: Click on the button, then it brings 3 random cards (that are images of cards in my data set) from a deck of 22 cards.

What is happening: It is bringing the same few combinations of cards and it is not actually random and some cards never shows up.

Here is my code:

export function button7_click(event) {

// clear any filters in the dataset
$w("#dynamicDataset").setFilter( wixData.filter() );

// get size of collection that is connected to the dataset
let count = $w("#dynamicDataset").getTotalCount();

// get random number using the size as the maximum
let idx = Math.floor(Math.random() * count-1);

// set the current item index of the dataset
$w("#dynamicDataset").setCurrentItemIndex(idx);
}

What can I do to bring really random spread of 3 cards?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

JavaScript's Math.random() function is fast, but it has issues. First, it's not seedable, second, its randomness leaves little to be desired. According to the Birthday Paradox, the existence of duplicate values ​​does not mean that they are random. Although there are many ways to change the Random number pattern in JavaScript, here are three different methods adopted by the community:

  1. Seedable Random Number Generator Algorithm: This algorithm allows to generate a seedable random number generator in Javascript that you can tweak to generate a deterministic random number sequence. Browsers do not provide a built-in way to seed Math.random(), so this solution is useful both when you need a completely predictable repeatable pseudo-random sequence and when you need a robust seed that is much more unpredictable than your browser's.
  2. Mersenne Twister: This algorithm compensates for not being allowed to specify an initial value for Math.random().
  3. Alea, PRNG Algorithm: A Pseudo-Random Number Generator (PRNG) is an algorithm for generating a sequence of numbers whose properties approximate those of sequences of random numbers. The Alea package implements this algorithm.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!