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:
parent
146cf55f23
commit
8833043f02
@ -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]
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user