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: Fri, 2 Feb 2018 17:05:21 -0600
Date: 2018-02-02T17:05:21-06:00	[thread overview]
Message-ID: <p52qrh$hev$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 8c806572-009d-4ba2-a20d-de1209e45ca6@googlegroups.com

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


  parent reply	other threads:[~2018-02-02 23:05 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 [this message]
2018-02-03  8:17           ` Jeffrey R. Carter
2018-02-03 16:59           ` Robert Eachus
2018-02-06  0:39             ` Randy Brukardt
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