From 951564a9eb762fd8e031269e18970572eff46fb8 Mon Sep 17 00:00:00 2001 From: Liliana Date: Wed, 13 Mar 2024 19:29:23 +0100 Subject: [PATCH] sonarcloud problem solved (??) --- webapp/src/components/FirstGame.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/FirstGame.js b/webapp/src/components/FirstGame.js index d3789cf6..e11e9589 100644 --- a/webapp/src/components/FirstGame.js +++ b/webapp/src/components/FirstGame.js @@ -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 @@ -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];