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.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Lotto simulation Date: Sun, 15 Jun 2014 15:09:10 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <77cc4476-8c57-481b-afb9-8f53f8b16e37@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 15 Jun 2014 22:09:12 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="ba346f17b503f6aa8ecbfd6d1e2a9f59"; logging-data="27805"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sFDGWXsn7z+uQr+lsZ14iOwnWl2j//Dw=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <77cc4476-8c57-481b-afb9-8f53f8b16e37@googlegroups.com> Cancel-Lock: sha1:BZ4wMjrK9tK4c0KvHsOrIKx/t6g= X-Original-Bytes: 2611 Xref: number.nntp.dca.giganews.com comp.lang.ada:186943 Date: 2014-06-15T15:09:10-07:00 List-Id: On 06/15/2014 10:07 AM, 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. I would usually define type Lotto_List is array (T1_49) of T1_49; List : Lotto_List; Then fill List so that it contains (1 => 1, 2 => 2, 3 => 3, ...). Then, for I in List'range, select a random Index, and swap the values in I and Index. Finally, use the values in List (1 .. 6). That doesn't have the same probabilities as picking 6 balls out of 49. If you want that, you have to do for I in List'First .. List'Last - 1 loop select random Index in I + 1 .. List'Last swap I and Index end loop; which is a little more complex if you use Discrete_Random. The random number generators in the PragmAda Reusable Components all come with functions to return a value in an integral range, so I generally use one of them rather than one of the predefined generators. http://pragmada.x10hosting.com/pragmarc.htm -- Jeff Carter "This trial is a travesty. It's a travesty of a mockery of a sham of a mockery of a travesty of two mockeries of a sham. ... Do you realize there's not a single homosexual on that jury?" Bananas 27