comp.lang.ada
 help / color / mirror / Atom feed
* Lotto simulation 2
@ 2014-06-16  8:03 montgrimpulo
  2014-06-16 12:21 ` Stefan.Lucks
  2014-06-16 20:59 ` john
  0 siblings, 2 replies; 3+ messages in thread
From: montgrimpulo @ 2014-06-16  8:03 UTC (permalink / raw)


Hi,

I want to thank all contributors to my first post on Lotto simulation for their valuable input.
As a conclusion I decided to use the containers.vectors package. Here is my solution. Please
feel free to comment on any aspect.

with Ada.Numerics.Discrete_Random, Ada.Text_IO, Ada.Containers.Vectors;
use Ada.Containers;

procedure Ziehung is
   package IO renames Ada.Text_IO;
   package ball_container is new Vectors (Positive, Positive);
   balls, iball : ball_container.Vector;
   tz, iz       : Integer;
begin
   balls.Set_Length (Length => 49);
   iball.Set_Length (Length => 6);

   for i in 1 .. 49 loop
      balls.Replace_Element (Index => i, New_Item => i);
   end loop;

   tz := 49;
   for i in 1 .. 6 loop
      lottoblock : declare
         subtype z is Positive range 1 .. tz;
         package lb is new Ada.Numerics.Discrete_Random (z);
         glb : lb.Generator;
      begin
         lb.Reset (glb);
         iz := lb.Random (glb);
      end lottoblock;
      iball.Replace_Element
      (Index => i, New_Item => balls.Element (Index => iz));
      balls.Delete (Index => iz, Count => 1);
      tz := tz - 1;
   end loop;

   IO.Put_Line ("Length_b:" & balls.Length'Img);
   IO.Put_Line ("Length_ib:" & iball.Length'Img);

end Ziehung;

Length_b: 43
Length_ib: 6

[2014-06-16] process terminated successfully, elapsed time: 00.21s

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-16 20:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-16  8:03 Lotto simulation 2 montgrimpulo
2014-06-16 12:21 ` Stefan.Lucks
2014-06-16 20:59 ` john

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