id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 920,Proposed extension to random library,nobody,jmaurer,"{{{ I suggest adding the following utility function to the random library (with perhaps a name change): // PURPOSE: Sample from a set of N values given the // sequence p[1], p[1] + p[2], p[1] + p[2] + p[3], ... // of cumulative probabilities. // // REQUIRE: // - Type Incrementer supports the pre-increment // operation and equality comparison. Typically, // Incrementer will be an integral type or a // forward iterator. // - Pre-incrementing i some finite number of times // -- say, N -- makes it equal to iend. // - cumprob_it ""points"" at a nondecreasing sequence // of at least N nonnegative numbers, with the N-th // value in the sequence being equal to 1.0. // // RETURNS: // A random value in the interval [i, iend), with // cumprob_it defining the sequence of cumulative // probabilities. template Incrementer rand(Incrementer i, Incrementer iend, InputIterator cumprob_it, UniformRandomNumberGenerator & rng) { typedef std::iterator_traits::value_type number_t; uniform_01 urng(rng); number_t p = urng(); for ( ; p >= *cumprob_it; ++cumprob_t) { ++i; assert(!(i == iend)); } return i; } -- Kevin S. Van Horn (Kevin_VanHorn@ndsu.nodak.edu) }}}",Feature Requests,closed,,random,None,Problem,fixed,,