mercredi 20 janvier 2021

Randomize to evenly present elements in react

I'm trying to display elements from an array on a site built with React, but randomized so that whenever people come to the site, they see a randomized element of the array. Right now, I use a simple random index:

const randomIndex = keys[Math.floor(Math.random() * keys.length)];

to get a randomized element in the array. However, I want to be able to evenly present elements randomly (basically like Qualtrics' Randomizer: Evenly Present Elements function. Essentially, I want to ensure that each of the array elements is roughly presented a equal number of times across all site visitors.

Does anyone have any idea how to do that in React? Thank you so much!




Aucun commentaire:

Enregistrer un commentaire