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!.POSTED!not-for-mail From: "Jeffrey R. Carter" 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: Sat, 3 Feb 2018 09:17:41 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <87y3ki743m.fsf@jacob-sparre.dk> <40142b86-fdcf-49d3-bee7-2fdbb04c6db0@googlegroups.com> <8c806572-009d-4ba2-a20d-de1209e45ca6@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 3 Feb 2018 08:17:42 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="3eb55e3654e191bce4759159fc329546"; logging-data="6493"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19l4XUsImQ721gfQ5XDZCGATafpG5qCTn4=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:q5IQ/jg/xlp2VCigRp3QW4H0Gnw= Xref: reader02.eternal-september.org comp.lang.ada:50286 Date: 2018-02-03T09:17:41+01:00 List-Id: On 02/03/2018 12:05 AM, Randy Brukardt wrote: > > 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. The PragmAda Reusable Components have functions to obtain a uniformly distributed integer in a range from a uniformly distributed floating-point (psuedo-) random value (PragmARC.Real_Random_Ranges.Random_Int), and from a uniformly distributed random Unsigned_32 (PragmARC.Random_Ranges). A lot of effort went into convincing oneself that these were done correctly. No one has reported any problem with them, but no one has said that they are correct, either. https://github.com/jrcarter/PragmARC -- Jeff Carter "I spun around, and there I was, face to face with a six-year-old kid. Well, I just threw my guns down and walked away. Little bastard shot me in the ass." Blazing Saddles 40