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 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!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Random number generation Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <864o9vbkwz.fsf@gareth.avalon.lan> Date: Thu, 30 Dec 2010 14:04:05 +0100 Message-ID: NNTP-Posting-Date: 30 Dec 2010 14:04:03 CET NNTP-Posting-Host: 7168bfe8.newsspool1.arcor-online.net X-Trace: DXC=KkkP]FRfHHkPKPPVf;4hUjic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgbniX0T=6Vh`h[6LHn;2LCVn[j;Pm;;;;a:jfRK10D80b X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:17225 Date: 2010-12-30T14:04:03+01:00 List-Id: On Thu, 30 Dec 2010 11:43:40 +0100, Mart van de Wege wrote: > Anyone care to at least point me to some documentation that explains > what I'm doing wrong? Random generator is a stateful object, thus it cannot be local. I suggest this is what you want: -------------------------------------------------------------------------- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Numerics.Discrete_Random; procedure Rolltest is package Uniform is new Ada.Numerics.Discrete_Random (Natural); use Uniform; function Roll ( Dice : Generator; Number : in Positive; Size : in Positive; Modifier : in Integer := 0 ) return Integer is Result : Integer := 0; begin for I in 1..Number loop Result := Result + Random (Dice) mod Size; end loop; Result := Result + Modifier + Number; return Result; end Roll; Dice : Generator; begin Reset (Dice); for I in 1..10 loop Put (Roll (Dice => Dice, Number => 3, Size => 6)); end loop; end Rolltest; ------------------------------------------------------------------------- I added Number to the accumulated result because you did so in your example by choosing the range 2..Size. BTW, a sum of n realizations of a uniformly distributed random number is distributed uniformly with the factor n. So you need not to run a cycle within Roll: function Roll ( Dice : Generator; Number : in Positive; Size : in Positive; Modifier : in Integer := 0 ) return Integer is begin return Number * ((Random (Dice) mod Size) + 1) + Modifier; end Roll; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de