psychojs
psychojs copied to clipboard
Alias all numpy.random functions which PsychoPy imports
I noticed some discrepancies between the random functions in utils and their numpy counterparts. The functions themselves seem simple enough that my rudimentary JS should be adequate so I had a go at bringing about parity. Apart from numpy.random.normal - for which I've just added an exception to be a bit more informative.
I've done some testing just from copying the functions to a script and running it in an HTML file, but please do run it through the proper test suite! My tests were:
console.log([random(), random(), random(), random(), random(),])
console.log(random(5))
console.log([randint(4), randint(4), randint(4), randint(4), randint(4),])
console.log(randint(5))
console.log(randint(2, 4, 5))
console.log(shuffle([1, 2, 3]))
console.log(shuffle([1, 2, 3]))
console.log(shuffle([1, 2, 3]))
console.log(randchoice([1, 2, 3], 3, false, [0.5, 0.1, 0.1]))
console.log(randchoice([1, 2, 3], 3, false, [0.5, 0.1, 0.1]))
console.log(randchoice([1, 2, 3], 3, false, [0.5, 0.1, 0.1]))
console.log(randchoice([1, 2, 3], 5, true, [0.5, 0.1, 0.1]))
which seemed to behave as expected