1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-11 16:18:10 +00:00

FF: Select random index rather than shuffling and indexing -1

This commit is contained in:
Todd 2021-08-19 16:22:39 +01:00
parent 146cf55f23
commit 8833043f02

View File

@ -370,8 +370,12 @@ export function shuffle(array, randomNumberGenerator = undefined)
*/
export function randchoice(array, randomNumberGenerator = undefined)
{
let shuffledArray = shuffle(array, randomNumberGenerator=randomNumberGenerator)
return shuffledArray.slice((- 1))[0];
if (randomNumberGenerator === undefined)
{
randomNumberGenerator = Math.random;
}
const j = Math.floor(randomNumberGenerator() * array.length);
return array[j]
}
/**