cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Lotto game

ValeryOchkov
24-Ruby IV

Lotto game

Friends, I need a function that returns a vector containing n natural random non-repeating numbers (Lotto game)

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:ValeryOchkov)

With all numbers from 0 to n-1:

LucMeekes_0-1671029454648.pngLucMeekes_1-1671029464121.png

 

or n out of N, where N is much larger:

LucMeekes_2-1671029623196.pngLucMeekes_3-1671029631537.png

 

Success! ( with the Christmas lottery?)

Luc

 

Mathcad and Prime express files attached.

View solution in original post

7 REPLIES 7
LucMeekes
23-Emerald III
(To:ValeryOchkov)

With all numbers from 0 to n-1:

LucMeekes_0-1671029454648.pngLucMeekes_1-1671029464121.png

 

or n out of N, where N is much larger:

LucMeekes_2-1671029623196.pngLucMeekes_3-1671029631537.png

 

Success! ( with the Christmas lottery?)

Luc

 

Mathcad and Prime express files attached.

Thanks, but Mathcad 15

ValeryOchkov_0-1671087684060.png

 

You may use

Werner_E_1-1671089657435.png

or even better

Werner_E_2-1671089863548.png

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

Werner_E_3-1671090208234.png

 

 

 

 

ValeryOchkov_0-1671384470624.png

ValeryOchkov_1-1671384723033.jpeg

 

 

SMath

ValeryOchkov_0-1671385842031.png

 

Werner_E
25-Diamond I
(To:Werner_E)

@ValeryOchkov 

> 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.

Werner_E_0-1671382991012.png

 

Announcements

Top Tags