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/18 Message-ID: #1/1 X-Deja-AN: 243034603 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-18T00:00:00+00:00 List-Id: In article <01bc63a2$e3e1a940$LocalHost@xhv46.dial.pipex.com>, "Nick Roberts" wrote: >It is interesting to note that if a program creates many generators seeded >by the clock all at (very nearly) the same time, it runs the risk >(depending on the resolution of the clock) of all those generators (or many >of them) being seeded with the same seeds, and therefore generating exactly >the same sequences of numbers. It is on this issue which Robert Eachus was >writing (I think). Are there any practical situations where this might be a >problem? Funny you should bring that up. We just wrote a small application with 10 tasks, where each one wakes up every 5 seconds to check a randomly-generated temperature. In spite of the fact that each task had its own generator, each one yielded the same value. This was undoubtedly caused by the fact the each generator had been (automatically) seeded with the same time. Here's what we did to solve the problem, but it didn't work. Instead of each task having its own generator, we made one generator, and wrapped it in a protected object. When each task woke up, it called a protected function that returned the random value: protected Generator is function Random return Temperature; private G : Random_Temperatures.Generator; end; protected body Generator is function Random return Temperature is begin return Random_Temperatures.Random (G); end; end; I assumed each invokation of Generator.Random would return a different random number (or at least random numbers evenly distributed about the range of temperature), but this isn't so. Every 5 seconds, all 10 tasks would wake up and call the protected object. I thought that these 10 invokations would generate different random values, but all 10 tasks received the same random value. The value would change every 5 seconds, but all 10 tasks would get that same value. This was my first time using a protected object, and perhaps I have misused it somehow. Maybe a state-changing protected procedure would force a new random number to be generated when invoked, and it was incorrect to use a protected function. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271