comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Lotto simulation
Date: Sun, 15 Jun 2014 15:09:10 -0700
Date: 2014-06-15T15:09:10-07:00	[thread overview]
Message-ID: <lnl5i7$r4t$1@dont-email.me> (raw)
In-Reply-To: <77cc4476-8c57-481b-afb9-8f53f8b16e37@googlegroups.com>

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


  parent reply	other threads:[~2014-06-15 22:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-15 17:07 Lotto simulation montgrimpulo
2014-06-15 18:54 ` Stefan.Lucks
2014-06-15 19:53   ` J-P. Rosen
2014-06-16  5:25     ` Stefan.Lucks
2014-06-16  7:49       ` J-P. Rosen
2014-06-16 11:15         ` Stefan.Lucks
2014-06-16 13:40           ` J-P. Rosen
2014-06-16 14:13             ` Natasha Kerensikova
2014-06-16 17:51             ` Randy Brukardt
2014-06-15 19:56 ` Denis McMahon
2014-06-15 20:10 ` Dirk Heinrichs
2014-06-15 20:43   ` Simon Wright
2014-06-16 20:22     ` Dirk Heinrichs
2014-06-15 20:54 ` Simon Wright
2014-06-15 22:09 ` Jeffrey Carter [this message]
2014-06-16 11:40 ` Markus Schöpflin
2014-06-16 14:25   ` Jacob Sparre Andersen
2014-06-16 12:02 ` Dmitry A. Kazakov
replies disabled

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