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 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!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mart van de Wege Newsgroups: comp.lang.ada Subject: Re: Random number generation Date: Thu, 30 Dec 2010 13:16:08 +0100 Message-ID: <86tyhva22f.fsf@gareth.avalon.lan> References: <864o9vbkwz.fsf@gareth.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net B69di5h6G+amIwKvAspFCwkaOOUb7WZpDkT5SevCIt4w16nDYy X-Orig-Path: gareth.avalon.lan!not-for-mail Cancel-Lock: sha1:a/tXxN6UuPpyZsfumo6cf4EnJ3Q= sha1:aWhND5Ir7UBhWSksdEdJpzgeRCw= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Xref: g2news2.google.com comp.lang.ada:17223 Date: 2010-12-30T13:16:08+01:00 List-Id: Brian Drummond writes: > On Thu, 30 Dec 2010 11:43:40 +0100, Mart van de Wege wrote: > > Check the documentation for Ada.Numerics.Discrete_Random or at least its > specification ( .ads file) but I think you'll find you need to reset the Die > exactly once, rather than every call of the Roll function. > > As I understand, you are resetting the seed each time, so you get the same > results! > > The shortest way to resolve this is to make Die a global variable and reset it > at the start of the main program - in the context of a one-page beginner's > program it's a reasonable thing to do. > > We're all taught "Global Variables are BAD" with good reason, so - once you have > resolved the immediate problem - it might be a good time to learn a bit about > packages, to hide the Die and expose only what you need to operate on it. > Heh. This function *was* living in a package. I abstracted it out into a test program to isolate it and make it short enough to copy/paste here. But thanks. The problem is with my re-initialising the generator every time, and like others pointed out, the code is running fast enough that the generator gets the same seed every time; that is, if I understand everything correctly now. Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.