20 lines
448 B
JavaScript
20 lines
448 B
JavaScript
function rand(arr) {
|
|
return arr[Math.floor(Math.random() * arr.length)];
|
|
}
|
|
|
|
export function shouldWin() {
|
|
return Math.random() < 1 / 7;
|
|
}
|
|
|
|
export function pickResults(symbols, forceWin) {
|
|
if (forceWin) {
|
|
const s = rand(symbols);
|
|
return [s, s, s];
|
|
}
|
|
let results;
|
|
do {
|
|
results = [rand(symbols), rand(symbols), rand(symbols)];
|
|
} while (results[0].id === results[1].id && results[1].id === results[2].id);
|
|
return results;
|
|
}
|