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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2ac1e7c090dd0c4a,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!a39g2000pre.googlegroups.com!not-for-mail From: DarthBob88 Newsgroups: comp.lang.ada Subject: "Constraint Error: Range Check" That Does Not Always Occur Date: Wed, 21 Nov 2007 22:42:19 -0800 (PST) Organization: http://groups.google.com Message-ID: <86ddf1f4-c7be-4729-8480-bae618b6d296@a39g2000pre.googlegroups.com> NNTP-Posting-Host: 209.216.178.5 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1195713739 24096 127.0.0.1 (22 Nov 2007 06:42:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 22 Nov 2007 06:42:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a39g2000pre.googlegroups.com; posting-host=209.216.178.5; posting-account=Wx82cgoAAACNa4nrJhRV8xCn3wMN2wR_ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9,gzip(gfe),gzip(gfe) Content-Disposition: inline Xref: g2news1.google.com comp.lang.ada:18557 Date: 2007-11-21T22:42:19-08:00 List-Id: I've been trying to write a program that creates four random numbers, to simulate four dice rolling; a D&D simulator, in fact. Unfortunately, I occasionally get "raised CONSTRAINT_ERROR : test.adb: 22 range check failed" (line 22 is one of the lines to generate a random number; it varies between the four). I have been trying to find information on how to prevent this error, but I can't find anything about it. I'm extremely new to this language, as in I only started last week new, so any help would be greatly appreciated. Here follows my code, warts and all. with Ada.Text_IO, Ada.Integer_Text_IO; with Ada.Numerics.Discrete_Random; procedure test is subtype Die is Integer range 1..6; --Declare that anything of type Die may be --an integer, value between 1 and 6, inclusive, and sod-all else. subtype Dice is Integer range 3*Die'First .. 3*Die'Last; --Declares that Dice may be anything from 3 to 18. package Random_Die is new Ada.Numerics.Discrete_Random (Die); use Random_Die; --Random generator; produces an integer between 1 and 6 sum : Integer := 0; G: Generator; D1 : Dice; D2 : Dice; D3 : Dice; D4 : Dice; --Declare four Dice begin Reset(G); D1 := Random(G); D2 := Random(G); D3 := Random(G); D4 := Random(G); --I Haven't found the error just yet, but a Constraint_Error --Occasionally comes up for the previous 4 lines --I haven't been able to find it online, but I presume --It's because the generator comes up with a number outside of [1,6] sum := D1 + D2 + D3 + D4; --Debugging Ada.Integer_Text_IO.Put(D1); Ada.Integer_Text_IO.Put(D2); Ada.Integer_Text_IO.Put(D3); Ada.Integer_Text_IO.Put(D4); Ada.Integer_Text_IO.Put(sum); end test; --compile Ada programs with gnat make .adb If it helps any, I'm using the Windows version of GNAT on XP. Thanks in advance.