The other evening when playing bridge, one player was dealt a hand containing 26 points. I then wondered what the probability was and thought: just the job for a simple program.

Background: each bridge player is dealt 13 of the 52 cards. Simple points values are 4 for an Ace, 3 for a King, 2 for a Queen and 1 for a Jack (Knave).

Program: I arbitrarily distribute 4 lots of 4 points, 3 points, 2 points and 1 point through the 52-card pack - the array elements Pack%%(n, 0). Then I randomly select 13 of the 52 cards and add up the points value - variable CardsValue%%. For each points value obtained I calculate the probability of obtaining that value over many deals - elements Probs~&&(CardsValue%%, 0) and also the probability of getting that value or greater Probs~&&(CardsValue%%, 1).

The program I have written gives zero probability for points values 30 and 32 to 37. They should have very small values, but not zero (you could get up to 37: 4 Aces, 4 Kings, 4 Queens and a Jack).

I wonder if you could find out where I have gone wrong. It is strange that I should be able to make such an elementary error - don't tell Fellippe, he'll bar me from the site!

Petr, I don't think that that's the error. Elements Probs~&&(CardsValue%%, 0/1) ARE integers: they are counted up by 1 if that points value is obtained. The probabilities (definitely decimal) are obtained by dividing Probs~&&() by Count~&& (also a large integer).

bplus, thanks. I tried a different shuffling method in my code and still got an error (although results not the same as my 1st attempt). I think that I'm not understanding RND properly. I'm assuming that yours is correct: the likelihood of being dealt anything above 32 points is extremely low.

bplus, I replaced my shuffling method with yours (Fisher-Yates or Knuth shuffle: who they?) in my code, and unsurprisingly I now get good results. So I am not quite understanding RND. This makes one feel suspicious of one's intelligence!

bplus, I replaced my shuffling method with yours (Fisher-Yates or Knuth shuffle: who they?) in my code, and unsurprisingly I now get good results. So I am not quite understanding RND. This makes one feel suspicious of one's intelligence!

Int(RND * N) gives a range of Integers from 0 to N-1, so if you want the range from 1 to N just add 1 for good results.

I did manage to get that bit of RND right (thank goodness). It's what I was doing with the numbers thus generated that was somehow wayward. It was odd that my first two attempts were only a little in error. I have since found that my original routine had a SWAP condition where the SWAP elements could be the same. With that condition removed, even my method works. This project now completed. Thanks.

Only for points count above 31 (where the probabilities are very low) do we see disagreement. In the program, run for 1000000000 hands, the numbers of hands occurring with 32 or more points are few (and zero for 36 and 37).

'reduce terms in a52_39 by terms in denominator mult 2 to 13FOR i = 13 TO 2 STEP -1 found = 0 FOR j = 1 TO 13 'is the array item divisible by i IF a52_39(j) MOD i = 0 THEN a52_39(j) = a52_39(j) \ i: found = 1: EXIT FOR NEXT IF found = 1 THEN a13(i) = 1 ELSE a13(i) = iNEXT