mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-12 08:38: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)
|
export function randchoice(array, randomNumberGenerator = undefined)
|
||||||
{
|
{
|
||||||
let shuffledArray = shuffle(array, randomNumberGenerator=randomNumberGenerator)
|
if (randomNumberGenerator === undefined)
|
||||||
return shuffledArray.slice((- 1))[0];
|
{
|
||||||
|
randomNumberGenerator = Math.random;
|
||||||
|
}
|
||||||
|
const j = Math.floor(randomNumberGenerator() * array.length);
|
||||||
|
return array[j]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user