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: border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!feeder.erje.net!eu.feeder.erje.net!news-2.dfn.de!news.dfn.de!news.uni-weimar.de!medsec1.medien.uni-weimar.de!lucks From: Stefan.Lucks@uni-weimar.de Newsgroups: comp.lang.ada Subject: Re: Lotto simulation Date: Sun, 15 Jun 2014 20:54:14 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <77cc4476-8c57-481b-afb9-8f53f8b16e37@googlegroups.com> NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-2057582797-1402858456=:4330" X-Trace: pinkpiglet.scc.uni-weimar.de 1402858399 12359 141.54.178.228 (15 Jun 2014 18:53:19 GMT) X-Complaints-To: news@pinkpiglet.scc.uni-weimar.de NNTP-Posting-Date: Sun, 15 Jun 2014 18:53:19 +0000 (UTC) X-X-Sender: lucks@debian In-Reply-To: <77cc4476-8c57-481b-afb9-8f53f8b16e37@googlegroups.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) X-Original-Bytes: 3694 Xref: number.nntp.dca.giganews.com comp.lang.ada:186930 Date: 2014-06-15T20:54:14+02:00 List-Id: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-2057582797-1402858456=:4330 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Sun, 15 Jun 2014, montgrimpulo wrote: > this is a placeholder of the task which I am trying to solve in Ada. > As you may know in German Lotto there are 49 numbers 1..49 > from which you have to select 6 numbers to place a bet. > > First Round: > By defining a subtype valid for positive numbers from 1 .. 49, > the use of Ada.Discrete_Random, and the definition of an appropriate Gene= rator > you may get a random number in the range of 1 .. 49. Call that number R_1. > Second Round: > Here does my problem start. Now I have a set of numbers where > one number - which was randomly selected in the first round - > is missing. How do I use the random function to select another > random number out of the rest ? There are a couple of different solutions. First Solution (in pseudo-code, not in Ada): repeat choose a random R_2 between 1 and 49=20 until R_2 /=3D R_1. Third round: Choose a random R_3 between 1 and 49 until R_3 /=3D R_1 and R_3 /=3D R_2. ect. Second Solution: choose a random R_2 between 1 and 48 If R_2=3DR_1 then R_1 :=3D 49 choose a random R_3 between 1 and 47 If R_3=3DR_1 then R_3 :=3D 48 elsif R_3=3DR_2 then R_3 :=3D 49 ect. Now, for the second solution, you need random numbers from different=20 intervals. In principle, you can (2a) instantiate a new generator from=20 Ada.Numerics.Discrete_Random for each of the R_i. The alternative is to=20 (2n) instantiate a single random generator (I've forgotten the package=20 name, but it is not A.N.Discrete_Random), which just generates a Float=20 F_Rand between 0 and 1. Then set R_I :=3D Truncate(1 + F_Rand * (50-I)). > A workaround would be > to test in each round, if that number has already been selected. > However, the probability would not be the same as with a reduced > set as the selection would be always from the full set. That sounds like my first solution. If you repeat the random choice until= =20 you R_i is different from all the R_(i-1), ..., R_1, the probability is=20 exactly the probability you expect. (Well, assuming the random generator=20 is good.) ------ I love the taste of Cryptanalysis in the morning! ------ --Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universit=E4t Weimar, Germany-- --8323329-2057582797-1402858456=:4330--