From: julio@diegidio.name   
      
   On Monday, 30 January 2023 at 05:00:45 UTC+1, Tim Rentsch wrote:   
      
   > Problem: rng is a random number generator function that returns   
   > values uniformly distributed between 0 and rng_max, inclusive (so   
   > rng_max+1 possible values. Choose k+1 distinct random values (using   
   > the supplied function rng) in the range between 0 and n, inclusive   
   > (so n+1 possible values).   
      
   That rng_max is really an error since it introduces a double step   
   that does not exist in reality (if you can instantiate an rng for the   
   range [0,rng_max], then you can as well directly instantiate one   
   for the range [0,n]). The requirement indeed boils down to   
   generating k+1 random numbers in the range [0,n]. If your intent,   
   as I guess, was to have one explicitly code the transformation of   
   range, you should have asked for an rng that (as usual) returns   
   numbers in [0,1[.   
      
   > Of these k+1 distinct values, return the   
   > j'th value in ascending order (so for j=0 return the least value,   
   > for j=k return the largest value, etc).   
      
   I don't think better can be done than:   
   1. loop to generate the random numbers   
    1.*. insert sorted into a containing array (ascending)   
   2. return the j-th element of the array.   
      
   Julio   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|