From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Card game deck but with trumps suit for tarot "divination" Is there a better way than enumerating all cards? Date: Mon, 5 Feb 2018 18:39:13 -0600 Organization: JSA Research & Innovation Message-ID: References: <87y3ki743m.fsf@jacob-sparre.dk> <40142b86-fdcf-49d3-bee7-2fdbb04c6db0@googlegroups.com> <8c806572-009d-4ba2-a20d-de1209e45ca6@googlegroups.com> Injection-Date: Tue, 6 Feb 2018 00:39:14 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="14128"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:50311 Date: 2018-02-05T18:39:13-06:00 List-Id: "Robert Eachus" wrote in message news:d6f57d39-fede-4e6e-b0a1-a721a1379643@googlegroups.com... On Friday, February 2, 2018 at 6:05:23 PM UTC-5, Randy Brukardt wrote: >> >Why go through sorting the Long_Float values? If you draw without >> >replacement, you draw from 78 cards, then 77, 76, 75,...4,3,2,1. There >> >is nothing in Ada's random number generators to guarantee that these 78 >> >generators work together to produce random values. By choosing 78 >> >values from the same generator you don't have that problem. >> >> As previously noted, Ada 2020 has added an additional Random function >> into >> Discrete_Random to deal with this problem. >The reason to use Long_Float, or an even better generator if available is >that there >are 78! possible orders for the deck. If you use a generator with 2**24 >values, >there are lots of deck orders you can't generate. Even worse if the period >of the >PRNG is significantly less than the number of deals. (If you are dealing >the cards >into n hands of k cards, there are 78!/((k!)**n possible deals. For bridge >hands >(52 card deck, four hands) this is about 5.36x10**28, the tarot deck >doesn't >deal evenly into four hands, but you can deal it into two, three, six, or >13 hands. ;-) The definition of the Ada Discrete_Random generators is to give a uniform distribution for the given range. It also guarantees that all values will occur (eventually). It's very easy to get this wrong, so there is a strong benefit to using a predefined version that is much more likely to be correct. (I've written a number of incorrect discrete random generators over the years, which I guess demonstrates that effect.) For the vast majority of usages, the standard generator will be good enough. In all of the cases I've seen, it's built on top of Float_Random, so will have similar characteristics. Certainly, it is good enough to handle a few million deals (you want distinct results from those, you're not worried about generating all possible deals). If someone has really exacting requirements, they'll have to build your own random generator, so you can control the characteristics. But this sort of thing is for experts only. (Janus/Ada uses the generator provided by Ken Dritz during the Ada 9x work; he didn't provide an implementation of Discrete_Random, and I proved the point by getting that wrong. ;-) Randy.