From fdce3763e26d47caccbec27a5981abd0ad55d77a Mon Sep 17 00:00:00 2001 From: datalore Date: Fri, 3 Nov 2023 15:38:26 +0100 Subject: [PATCH] Implemented FisherYatesShuffle --- src/app/components/bingocontroller.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/components/bingocontroller.tsx b/src/app/components/bingocontroller.tsx index 7f93cf5..cd8dc28 100644 --- a/src/app/components/bingocontroller.tsx +++ b/src/app/components/bingocontroller.tsx @@ -3,6 +3,16 @@ import React from 'react' import Bingo from './bingo.tsx' +function FisherYatesShuffle(array:string[]):string[]{ + for(let i = array.length - 1; i > 0; i--){ + const j = Math.floor(Math.random() * (i + 1)); + const temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + return array; +} + export default function BingoController(){ const [size, setSize] = React.useState(5); const buzzwords = ["Cloud", "Cyber", "Distruptive Technology", "AI", "Metaverse", "Gamification", "Web 2.0/3.0", "Industry 4.0", "Internet of Things", "Multiexperience", "Big Data", "Crypto", "[Insert bullshit here] as a service", "Emerging Market", "Streamline"]; @@ -19,7 +29,7 @@ export default function BingoController(){ 4x4 5x5 - Regenerate + setItems(FisherYatesShuffle(buzzwords))}>Regenerate {sizeError &&
Warning: Mismatch between item count and size
}