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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8147387fe25d4e2a,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mart van de Wege Newsgroups: comp.lang.ada Subject: Random number generation Date: Thu, 30 Dec 2010 11:43:40 +0100 Message-ID: <864o9vbkwz.fsf@gareth.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net Uti80F7GGwhentzC7qmySg3QZjulUhqMvr/8G3RUkuoxXufJAp X-Orig-Path: gareth.avalon.lan!not-for-mail Cancel-Lock: sha1:zou6tz7LaDtNbTQ1ouo7qwiF2G4= sha1:vz9PcRgmH2CmYY9UEkk9pq1ZChc= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Xref: g2news1.google.com comp.lang.ada:16246 Date: 2010-12-30T11:43:40+01:00 List-Id: Beginner's question: I'm trying to implement a function that rolls a number of dice and then adds a modifier. Somehow, it produces the same number every time. I can't see where I'm going wrong. Here's the proof of concept code: with Ada.Numerics.Discrete_Random,Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Rolltest is function Roll ( Number : in Positive; Size : in Positive; Modifier : in Integer := 0 ) return Integer is subtype Die_Size is Positive range 2..Size; package Die is new Ada.Numerics.Discrete_Random( Die_Size ); G : Die.Generator; Result : Integer; Temp : Integer; begin Die.Reset(G); 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 for I in 1..10 loop Put(Roll( Number => 3, Size => 6 )); end loop; end Rolltest; Anyone care to at least point me to some documentation that explains what I'm doing wrong? Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.