Skip to content

Commit

Permalink
sonarcloud problem solved (??)
Browse files Browse the repository at this point in the history
  • Loading branch information
uo288574 committed Mar 13, 2024
1 parent 85108d2 commit 951564a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions webapp/src/components/FirstGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const Quiz = () => {
return new Promise(resolve => setTimeout(resolve, ms));
};

function secureRandomNumber(max) {
const randomBytes = new Uint32Array(1);
window.crypto.getRandomValues(randomBytes);
return randomBytes[0] % max;
}

function shuffleArray(array) {
// Crea una copia del array original
Expand All @@ -27,8 +32,9 @@ const Quiz = () => {
// Recorre el array desde el último elemento hasta el primero
for (let i = shuffledArray.length - 1; i > 0; i--) {
// Genera un índice aleatorio entre 0 y el índice actual
const randomIndex = Math.floor(Math.random() * (i + 1));

//const randomIndex = Math.floor(Math.random() * (i + 1));
const randomIndex = secureRandomNumber(i + 1);

// Intercambia el elemento actual con el elemento del índice aleatorio
const temp = shuffledArray[i];
shuffledArray[i] = shuffledArray[randomIndex];
Expand Down

0 comments on commit 951564a

Please sign in to comment.