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!gandalf.srv.welterde.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: Fri, 2 Feb 2018 17:05:21 -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: Fri, 2 Feb 2018 23:05:22 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="17887"; 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:50285 Date: 2018-02-02T17:05:21-06:00 List-Id: "Robert Eachus" wrote in message news:8c806572-009d-4ba2-a20d-de1209e45ca6@googlegroups.com... On Monday, January 29, 2018 at 6:17:01 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. An alternative approach using current Ada would be to use a fixed Discrete_Random range (0 .. 77), and simply discard any values that identify cards already dealt, just retrying to get a random value. This works well and is properly uniform, but only if you are going to deal part of the deck (say 25%). If you need to deal the whole deck, it can get slow toward the end when most of the values returned from Random have already been dealt. (That's especially bad if you forget to special case the last card to the dealt - you don't need a random choice to figure out which one that is after all of the rest have been dealt.) Experience shows that most users don't get this right, as did the discussion on the topic (in which many knowledgeable people suggested approaches which just don't work). I had to fix the Janus/Ada random number generator after that discussion, as it had made one of the mistakes as well. Randy.