Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Friends, I need a function that returns a vector containing n natural random non-repeating numbers (Lotto game)
Solved! Go to Solution.
With all numbers from 0 to n-1:
or n out of N, where N is much larger:
Success! ( with the Christmas lottery?)
Luc
Mathcad and Prime express files attached.
With all numbers from 0 to n-1:
or n out of N, where N is much larger:
Success! ( with the Christmas lottery?)
Luc
Mathcad and Prime express files attached.
Thanks, but Mathcad 15
You may use
or even better
because that way you chose numbers from 1 to n (and not from 0 to n-1) which may be more appropriate for a lottery.
A shorter variant without using "max" is
SMath
> Why not
Hmm, thats sure a possible way. But to answer that question: Because Luc's solution using "matrix" & "runif" is a bit shorter, faster (avoiding explicit loops) and so a bit more elegant 😄 Furthermore its ORIGIN-aware!
BTW, while I don't think the various elements of gamification here on the forum are really useful or helpful, it should still be Luc's answer that is marked as "the correct one" and not mine. Apart from the fact that I appreciate his elegant and short solution, the question did not specify the Mathcad version for which a solution is needed and his suggestions work in older versions like Mathcad 11 as well as in the current Prime versions. Just unfortunately not in MC14/15. I am not sure if this has something to do with SUC, that "matrix" in these versions does not accept built-in function, which have not explicitly only exactly two arguments.
EDIT: I see you already changed the "corrected answer".
So here is a more standard approach. Its not as elegant and short, but its faster because only one Nx1 matrix is created and the time-consuming "submatrix" is avoided.