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!border2.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!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 2 Date: Mon, 16 Jun 2014 14:21:21 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <7b5472cb-54c1-4bc4-b89b-8c72e4b72c7d@googlegroups.com> NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1033249114-1402921282=:6719" X-Trace: pinkpiglet.scc.uni-weimar.de 1402921227 25925 141.54.178.228 (16 Jun 2014 12:20:27 GMT) X-Complaints-To: news@pinkpiglet.scc.uni-weimar.de NNTP-Posting-Date: Mon, 16 Jun 2014 12:20:27 +0000 (UTC) X-X-Sender: lucks@debian In-Reply-To: <7b5472cb-54c1-4bc4-b89b-8c72e4b72c7d@googlegroups.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) X-Original-Bytes: 3546 Xref: number.nntp.dca.giganews.com comp.lang.ada:186963 Date: 2014-06-16T14:21:21+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-1033249114-1402921282=:6719 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE > 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. Looks OK, in principle. Some of your identifiers may be too short to=20 understand what is going on (e.g., tz, iz), and, when communicating Ada=20 source code, you should lean to capitalize identifiers (Tz or TZ, but not= =20 tz), ect ... Also, it is a little surprising that you don't output your results. However, my main criticism would be that your usage of Vectors is overkill= =20 for the problem at hand. Here is a solution using a single array, instead= =20 of two containers. with Ada.Numerics.Discrete_Random, Ada.Text_IO; procedure Ziehung2 is subtype Index is Integer range 1 .. 49; Ball: array(Index) of Index; begin -- intialize Ball for I in Index loop Ball(I) :=3D I; end loop; -- draw six numbers and print them for I in 0 .. 5 loop -- invariant: Ball(1 .. Index'Last-I) hold the balls not yet drawn -- Ball(Index'Last-I+1 .. Index'Last) hold the balls drawn so far declare =09 subtype Z is Index range 1 .. Index'Last-I; =09 package RND is new Ada.Numerics.Discrete_Random(Z); =09 Gen: RND.Generator; =09 Drawn, Tmp: Index; begin =09 RND.Reset(Gen); =09 Drawn :=3D Rnd.Random(Gen); -- Drawn :=3D random index =09 Ada.Text_IO.Put(Index'Image(Ball(Drawn))); -- print Ball(Drawn) =09 -- move Ball(Drawn) to the end of Ball(1 .. Index'Last-I) =09 -- more precisely, swap Ball(Index'Last-I) and Ball(Drawn) =09 Tmp :=3D Ball(Index'Last-I); =09 Ball(Index'Last-I) :=3D Ball(Drawn); =09 Ball(Drawn) :=3D Tmp; end; end loop; end Ziehung2 ------ I love the taste of Cryptanalysis in the morning! ------ --Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universit=E4t Weimar, Germany-- --8323329-1033249114-1402921282=:6719--