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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.ams.giganews.com!nntp.giganews.com!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: How to include shared code Date: Thu, 19 Sep 2013 09:20:52 +0200 Organization: cbb software GmbH Message-ID: <7yffm84xnlgw.1r5hqjn5kp2g9.dlg@40tude.net> References: <87zjr9u0ja.fsf@nl106-137-194.student.uu.se> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: IenaDxMXK2hi7fvYcb+MlQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: number.nntp.dca.giganews.com comp.lang.ada:183382 Date: 2013-09-19T09:20:52+02:00 List-Id: On Thu, 19 Sep 2013 02:17:52 +0200, Emanuel Berg wrote: > If I have two files: > > protected_buffer.adb > bounded_buffer.adb > > and those compile and run fine. > > But, in both those, I have this piece of code: > > function Random_Integer return integer is > type Span is range 1..9; > package Random_Integer is new Ada.Numerics.Discrete_Random(Span); > Seed : Random_Integer.Generator; > begin > Random_Integer.Reset(seed); > Outcome := Random_Integer.Random(seed); You should keep the generator object (and instantiation of its type) outside the function that calls it. You also would not reset it each time you call it. You do this just once after the generator object creation and only if you want the sequence generated to vary with each program start (see ARM A.5.2(28). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de