comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <jacob@jacob-sparre.dk>
Subject: Re: Lotto simulation
Date: Mon, 16 Jun 2014 16:25:51 +0200
Date: 2014-06-16T16:25:51+02:00	[thread overview]
Message-ID: <87oaxtvsls.fsf@adaheads.sparre-andersen.dk> (raw)
In-Reply-To: lnml37$9s2$1@speranza.aioe.org

Markus Schöpflin wrote:

> The easiest way AFAIK is to random shuffle an integer array containing
> the numbers 1 - 49 and then selecting the first six numbers from that
> array.
>
> Random shuffling can be achieved by filling a second array of the same
> size with random numbers obtained from a generator having a uniform
> distribution and then sorting this second array; moving the numbers
> from the first array in lock-step.

Another option could be to fill one array:

      type Balls is range 1 .. 49;
      type Ordered_List_Of_Balls is array (Balls) of Balls;
      Ordered_Balls : Ordered_List_Of_Balls
   begin
      for Ball in Ordered_Balls'Range loop
         Ordered_Balls (Ball) := Ball;
      end loop;

Then shuffle the balls in that array:

      for Primary in Ordered_Balls'Range loop
         Swap (List       => Ordered_Balls,
               Position_1 => Primary,
               Position_2 => Random (Generator));
      end loop;

... where I have assumed "sensible" declarations of Swap and Generator.

Greetings,

Jacob
-- 
Statistics is like a bikini - what it shows is very suggestive,
but the most important stuff is still hidden.

  reply	other threads:[~2014-06-16 14:25 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
2014-06-16 11:40 ` Markus Schöpflin
2014-06-16 14:25   ` Jacob Sparre Andersen [this message]
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