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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d1df6bc3799debed X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Not intended for use in medical, Date: 1997/05/19 Message-ID: #1/1 X-Deja-AN: 243080186 References: <3.0.32.19970423164855.00746db8@mail.4dcomm.com><01bc6006$c13cf880$LocalHost@xhv46.dial.pipex.com><01bc6182$30e3a7c0$LocalHost@xhv46.dial.pipex.com> <01bc63a2$e3e1a940$LocalHost@xhv46.dial.pipex.com> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-05-19T00:00:00+00:00 List-Id: In article , eachus@spectre.mitre.org (Robert I. Eachus) wrote: > Read what I wrote in the previous article for one solution to this >problem. Generate a seed from the clock--you can use the explicit >generator that does this, but: > > Seed: Integer := Integer(Float(Seconds(Calendar.Clock) * 1000)) > > is probably enough. Now pass Seed, Seed+1, Seed+2, etc. to the >appropriate version of Reset. Another solution is below: My post about initializing the discriminant of task that is a componant of an array was motivated by this problem. The idea was to use the task id - which was guaranteed to be unique - as the seed of the random number generator: task type T (Id : Integer) is entry E; end T; task body T is G : Generator; begin Reset (G, Initiator => Id); ... This solves the problem of using the clock as a seed, because there's no guarantee that all tasks will read a different time value (or at least time values that differ by more than 1 second - very unlikely). Robert Dewar is definately correct on this one: we need functions with in out mode parameters, in spite of what the pundits say. If function Random had had an in out parameter, I would have known at compile time that a protected function was illegal (and wouldn't work). Functions without side effect look great on paper, until you try to do real programming with that restriction. Robert's painful experience implementing the random number generator in GNAT is all the proof one needs to justify side-effect producing functions, and modifying the syntax to call out that fact. And my own experience - innocently calling Random from a protected function (compiles fine, but doesn't work) - is yet more evidence. The whole point of Ada is to detect "the things that won't work" at compile time. So now, before implementing a protected function, I have to make sure that any functions I call aren't causing side effect. With the current syntax, I can't determine that without reading the body of the function! It's not unlike the template model in C++. Stroustrup seems to have used parametric polymorphism as the model, and it looks great on paper, until you try to implement it in a real compiler. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271