comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to include shared code
Date: Thu, 19 Sep 2013 09:20:52 +0200
Date: 2013-09-19T09:20:52+02:00	[thread overview]
Message-ID: <7yffm84xnlgw.1r5hqjn5kp2g9.dlg@40tude.net> (raw)
In-Reply-To: 87zjr9u0ja.fsf@nl106-137-194.student.uu.se

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


      parent reply	other threads:[~2013-09-19  7:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-19  0:17 How to include shared code Emanuel Berg
2013-09-19  5:31 ` Peter Brooks
2013-09-19  6:24   ` Simon Wright
2013-09-19  7:20 ` Dmitry A. Kazakov [this message]
replies disabled

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