mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
Random consistent with randint for handling size
This commit is contained in:
parent
5e25a00189
commit
449ac750a7
@ -323,18 +323,17 @@ export function random(size = 1) {
|
||||
error: "size must be a positive integer above 0",
|
||||
};
|
||||
}
|
||||
|
||||
if (size === 1) {
|
||||
// if size is 1, return a single value
|
||||
return Math.random();
|
||||
} else {
|
||||
// if size is >1, return an array
|
||||
|
||||
if (size > 1) {
|
||||
// if size > 1, call function multiple times with size = 1 and return an array
|
||||
let values = []
|
||||
for (let i = 0; i < size; i++) {
|
||||
values.push(random(1));
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
return Math.random();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user