Skip to content

Commit 8c93a10

Browse files
Potential fix for code scanning alert no. 5: Creating biased random numbers from a cryptographically secure source
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 611b441 commit 8c93a10

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/2023/Home/components/SpeakersCarousel/SpeakerSwiper.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ export const shuffleArray = <T,>(array: T[]): T[] => {
4545
}
4646
const shuffledArray = [...array]; // Create a copy to avoid modifying the original array
4747
for (let i = shuffledArray.length - 1; i > 0; i--) {
48-
const j = Math.floor(
49-
(window.crypto.getRandomValues(new Uint32Array(1))[0] /
50-
(0xffffffff + 1)) *
51-
(i + 1),
52-
);
48+
let j;
49+
do {
50+
j = window.crypto.getRandomValues(new Uint32Array(1))[0] % (i + 1);
51+
} while (j >= (i + 1));
5352
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
5453
}
5554
return shuffledArray;

0 commit comments

Comments
 (0)