Re: Help With My Game of Black Jack
- Posted by Jiri Babor <J.Babor at GNS.CRI.NZ> Dec 01, 1999
- 632 views
David, Just a couple of minor points. Firstly, you did not properly initialize your deck. Secondly, in your shuffle, you call rand() twice per iteration. One is enough, it is an expensive operation. This is roughly what I have been using for the last 30 years: -- WARNING! TESTED CODE! sequence pack -- initialize pack pack = {} for i=1 to 52 do pack &= i end for procedure shuffle() integer dummy, r for i = 1 to 52 do r = rand(52) dummy = pack[r] pack[r] = pack[i] pack[i] = dummy end for end procedure Btw, for very obscure theoretical reasons, this is *not* the best possible shuffle, but it is still far better than what you can get by hand. jiri