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

pickRandom inconsistent behavior: returns array if receives an array of length=1 #983

Closed
moshetet opened this Issue Dec 7, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@moshetet

moshetet commented Dec 7, 2017

pickRandom([6,7]); //returns either 6 or 7
pickRandom([6]); //returns [6] instead of 6

Seen on Node 8.9.0

@harrysarson

This comment has been minimized.

Collaborator

harrysarson commented Dec 7, 2017

See http://mathjs.org/docs/reference/functions/pickRandom.html

The return type of math.pickRandom is documented as array so either it so the docs wrong.

The question is: should pickRandom

  1. Always return an array.
  2. Return an array if there are multiple values and the value if there is a single value.
@josdejong

This comment has been minimized.

Owner

josdejong commented Dec 9, 2017

I think that the idea is that pickRandom returns a single value like pickRandom([6,7]) does, unless you want it to return multiple values like pickRandom([1,2,3,4], 2), in which case it returns an array with the number of values that you configured.

So I think:

  • the documentation needs to be improved to clarify that
  • pickRandom([6]) returning [6] is a bug, should return 6 instead

@josdejong josdejong added the bug label Dec 9, 2017

@josdejong

This comment has been minimized.

Owner

josdejong commented Dec 9, 2017

Should be fixed now in the develop branch.

@josdejong josdejong closed this in 7df52c1 Dec 16, 2017

@josdejong

This comment has been minimized.

Owner

josdejong commented Dec 16, 2017

Should be fixed now in v3.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment