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 autolearn=ham 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-14 00:20:18 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!news.tele.dk!small.news.tele.dk!128.39.3.168!uninett.no!not-for-mail From: Reinert Korsnes Newsgroups: comp.lang.ada Subject: Re: Discrete random with given distribution ? Date: Fri, 14 Jun 2002 09:20:11 +0200 Organization: UNINETT Message-ID: References: <3D08AB63.6AF60F95@despammed.com> NNTP-Posting-Host: sthrkou.ffi.no Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: dolly.uninett.no 1024039346 29218 193.156.99.159 (14 Jun 2002 07:22:26 GMT) X-Complaints-To: news-abuse@uninett.no NNTP-Posting-Date: Fri, 14 Jun 2002 07:22:26 +0000 (UTC) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:25925 Date: 2002-06-14T09:20:11+02:00 List-Id: tmoran@acm.org wrote: >> type Rand_Val is (A1, A2, B, C); >> >> Lookup : array (Rand_Val) of Out_Type := >> (A1 => A, >> A2 => A, >> B => B, >> C => C); >> >> package Rand is >> new Ada.Numerics.Discrete_Random (Rand_Val); >> >> .... >> >> return Lookup (Rand.Random (Gen)); >>The first is awkward if the probabilities are complicated. > If your probabilites are expressed with three digit accuracy, for > instance, just make a 1000 element Lookup table with the right number of > A's, B's, and C's at initialization time. Few probabilities are > more precise than that. (If they appear to be, .3333... for instance, > create Lookup with an appropriate LCM size other than a power of ten.) Yep, the quickest method may be to "discretize" the probabilities. And the elements and their probabilities must in my case be given during runtime so the approach above must be somehow generalised. reinert