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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8147387fe25d4e2a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder3.cambriumusenet.nl!feeder2.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.105.MISMATCH!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 30 Dec 2010 16:29:00 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Random number generation References: <864o9vbkwz.fsf@gareth.avalon.lan> <8o3920Fn0vU1@mid.individual.net> <4d1c72cf$0$6772$9b4e6d93@newsspool3.arcor-online.net> <86pqsja1n3.fsf@gareth.avalon.lan> In-Reply-To: <86pqsja1n3.fsf@gareth.avalon.lan> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4d1ca53c$0$6765$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 30 Dec 2010 16:29:00 CET NNTP-Posting-Host: c63448dd.newsspool3.arcor-online.net X-Trace: DXC=hYd_EU?0H51D]ncZ]`hZ;1McF=Q^Z^V384Fo<]lROoR18kF:Lh>_cHTX3j=0U]:Q?XO026 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:17233 Date: 2010-12-30T16:29:00+01:00 List-Id: On 30.12.10 13:25, Mart van de Wege wrote: > Georg Bauhaus writes: >> >> OTOH, the Size parameter is fixed at 6, so subtype Die_Size and >> the generator could be placed outside Roll. Anyway, another >> nest will give suitable life times to the objects involved. >> > How does that work? Using another level of nesting to control life time and parameterization: procedure Rolltest is procedure Setup_And_Roll (Size: Positive) is subtype Die_Size is Positive range 2..Size; package Die is new Ada.Numerics.Discrete_Random( Die_Size ); G : Die.Generator; function Roll ( Number : in Positive; Modifier : in Integer := 0 ) return Integer is Result : Integer; Temp : Integer; begin Result := 0; for I in 1..Number loop Temp := Die.Random(G); Result := Result + Temp; end loop; Result := Result + Modifier; return Result; end Roll; begin Die.Reset(G); for I in 1..10 loop Put(Roll( Number => 3 )); end loop; end Setup_And_Roll; begin Setup_And_Roll (Size => 6); end Rolltest;