comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
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
Date: 2018-02-05T18:39:13-06:00	[thread overview]
Message-ID: <p5atfi$dpg$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: d6f57d39-fede-4e6e-b0a1-a721a1379643@googlegroups.com

"Robert Eachus" <rieachus@comcast.net> 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.


  reply	other threads:[~2018-02-06  0:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-28  7:48 Card game deck but with trumps suit for tarot "divination" Is there a better way than enumerating all cards? bozovic.bojan
2018-01-28  8:57 ` Jacob Sparre Andersen
2018-01-28  9:23   ` bozovic.bojan
2018-01-28  9:46     ` Jeffrey R. Carter
2018-01-28 14:17       ` bozovic.bojan
2018-01-28 16:39     ` Dennis Lee Bieber
2018-01-29 23:16     ` Randy Brukardt
2018-01-30  2:30       ` bozovic.bojan
2018-02-02 19:07       ` Robert Eachus
2018-02-02 23:00         ` Dennis Lee Bieber
2018-02-02 23:05         ` Randy Brukardt
2018-02-03  8:17           ` Jeffrey R. Carter
2018-02-03 16:59           ` Robert Eachus
2018-02-06  0:39             ` Randy Brukardt [this message]
2018-02-06  3:17               ` Robert Eachus
2018-02-06  8:30           ` Petter Fryklund
2018-02-07 20:03             ` Card game deck but with trumps suit for tarot "divination" Is there a better way Robert Eachus
2018-02-07 21:10               ` Bojan Bozovic
2018-02-08 23:06                 ` Robert Eachus
2018-01-28 11:01   ` Card game deck but with trumps suit for tarot "divination" Is there a better way than enumerating all cards? gautier_niouzes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox