Skip to content

Commit 12feb49

Browse files
Potential fix for code scanning alert no. 6: 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 8c93a10 commit 12feb49

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ export const shuffleArray = <T,>(array: T[]): T[] => {
4646
const shuffledArray = [...array]; // Create a copy to avoid modifying the original array
4747
for (let i = shuffledArray.length - 1; i > 0; i--) {
4848
let j;
49+
const max = (i + 1) * (2 ** 32 / (i + 1));
4950
do {
50-
j = window.crypto.getRandomValues(new Uint32Array(1))[0] % (i + 1);
51-
} while (j >= (i + 1));
51+
j = window.crypto.getRandomValues(new Uint32Array(1))[0];
52+
} while (j >= max);
53+
j = j % (i + 1);
5254
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
5355
}
5456
return shuffledArray;

0 commit comments

Comments
 (0)