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.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6e2278eaed9619d6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-16 15:12:45 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!cpk-news-hub1.bbnplanet.com!cambridge1-snf1.gtei.net!news.gtei.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3D0D0D48.B4B3156A@despammed.com> From: Wes Groleau Reply-To: wesgroleau@despammed.com X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en,es-MX,es,pt,fr-CA,fr MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Discrete random with given distribution ? References: <3D0A3AB5.281CDDB9@despammed.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sun, 16 Jun 2002 17:12:24 -0500 NNTP-Posting-Host: 151.168.144.162 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 1024265565 151.168.144.162 (Sun, 16 Jun 2002 17:12:45 CDT) NNTP-Posting-Date: Sun, 16 Jun 2002 17:12:45 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:26091 Date: 2002-06-16T17:12:24-05:00 List-Id: > >My first method must be determined before compile time > >(Actually, there is a way to approximate it at run-time, > >but it is a bit clumsy) > > >If the probabilities are to be determined at runtime, > >my second method will work, if you > Why not just use your second method (summing probabilities till you > hit a certain level) to calculate, at run time, the population of > a lookup table, then use the first method to speedily index into > it to pick a random element. That's what I meant by a bit clumsy. And it could be a fairly large lookup table, depending on how accurate you try to be. Size := 10 ** Digits_Of_Accuracy; Lookup : array ( 1 .. Size ) of Discrete_Things; Index := Lookup'First; for I in Discrete_Things loop Span := Integer (Probability (I)); for J in Index .. Index + Span - 1 loop Lookup (J) := I; end loop; Index := Index + Span; end loop; Hmmm, that's not as clumsy as I thought it would be. :-) -- Wes Groleau http://freepages.rootsweb.com/~wgroleau