Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias all numpy.random functions which PsychoPy imports #581

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

TEParsons
Copy link
Contributor

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

* @param {number} [size = 1] - number of values to return
* @returns {number} a random integer in the requested range (signed)
*/
export function randint(min, max = null, size = 1)
Copy link

@shun2wang shun2wang Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also raise errors if given non-integer negative range parameters like this:
randint(-10.1, 1) will return also a non-integer.

Otherwise everything looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants