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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.53.14 with SMTP id k14mr30381618ita.14.1517598452413; Fri, 02 Feb 2018 11:07:32 -0800 (PST) X-Received: by 10.157.14.146 with SMTP id 18mr989629otj.10.1517598452296; Fri, 02 Feb 2018 11:07:32 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!tncsrv06.tnetconsulting.net!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!g80no704506itg.0!news-out.google.com!s63ni1234itb.0!nntp.google.com!w142no703207ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 2 Feb 2018 11:07:31 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8303:2100:4863:7605:5c1d:6a14; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8303:2100:4863:7605:5c1d:6a14 References: <87y3ki743m.fsf@jacob-sparre.dk> <40142b86-fdcf-49d3-bee7-2fdbb04c6db0@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <8c806572-009d-4ba2-a20d-de1209e45ca6@googlegroups.com> Subject: Re: Card game deck but with trumps suit for tarot "divination" Is there a better way than enumerating all cards? From: Robert Eachus Injection-Date: Fri, 02 Feb 2018 19:07:32 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:50280 Date: 2018-02-02T11:07:31-08:00 List-Id: On Monday, January 29, 2018 at 6:17:01 PM UTC-5, Randy Brukardt wrote: =20 > I didn't look at your code to see if it is OK or not. If you do it wrong,= =20 > some cards would be more likely to be selected than others, which is like= ly=20 > to skew the results of your program. It also depends on whether you want selection with or without replacement. = To deal out a deck you want dealing without replacement (no two hands get = the Queen of Hearts, or whatever). The best way to deal with replacement is to use a Long_Float random number = generator then multiply by 78. Convert to Integer, and if 0, change to 78.= (Doesn't matter, if you do that, what type of rounding is used.) To shuffle a deck, make an array of 78 records with an Integer and a Long_F= loat. Assign the Integer field 1 through 78. Assign (78) random Long_Floa= ts to the other field, then apply whatever sort algorithm you wish. (I ten= d to use a generic heap sort, but with only 78 values, you will spend more = time setting things up and assigning random values than anything else.) Yo= u can either use these values to indirectly index into your cards, or just = add the Long_Float field and let the sort shuffle the card values. Why go through sorting the Long_Float values? If you draw without replacem= ent, 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 wor= k together to produce random values. By choosing 78 values from the same g= enerator you don't have that problem. Oh, what about assigning two equal (Long_Float) values to different cards? = If you really worry about it, with more than 2**56 values, think of the ca= rd number as a second index, and if two values are equal you look at the ca= rd number. You don't do this, you just choose a sort that maintains the or= iginal order when two values are the same.