Message Boards Message Boards

0
|
1923 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Explanation needed of a code contains "For" and "RandomSample"

Posted 3 years ago
POSTED BY: John Cena
4 Replies

Randomchoice can repeat selected values (equivalent to selecting a ball and the returning it to the drum for selecting the next number). Lotteries don’t do that. (A number is used only once). RandomSample does not allow repeats.

POSTED BY: Neil Singer
POSTED BY: Neil Singer
Posted 3 years ago

Thank you so much for the help, any idea as to why RandomSample would be used in this sinulated lottery draw over RandomChoice?

POSTED BY: John Cena

Luke,

  1. RandomSample[a, 7] randomly pulls 7 elements from a list (a) without any repeats This models a lottery ball machine because once a ball drops out, it can’t be used again.
  2. The numbers you are getting are indexes (i) so they have no real meaning. I.e. if you get 34521 it means on the 34521 th sample you happened to draw the lottery (a list that exactly matches b). The fact that you got four hits in 200,000,000 gives you a rough estimate of the odds of hitting the lottery.
  3. The code draws 7 numbers , sorts them numerically so it can be easily compared with the ticket (which must be in sort order). It then prints the index when it pulls a match.

I hope this helps.

Regards

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract