home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.programming      Programming issues that transcend langua      57,431 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 56,983 of 57,431   
   Tim Rentsch to Paul N   
   Re: Programming exercise - choose_k_of_n   
   30 Jan 23 07:48:45   
   
   From: tr.17687@z991.linuxsc.com   
      
   Paul N  writes:   
      
   > On Monday, January 30, 2023 at 4:00:45 AM UTC, Tim Rentsch wrote:   
   >   
   >> [choosing some distinct values using 'rng' for random numbers]   
   >   
   > Just to check, we're free to "use" rng any way we want to, as long as   
   > the results are unbiased?  For example, a naive approach might   
   > be to try again if we get a value bigger than n, but if rng_max  is   
   > between 2n+2 and 3n then we could have 0 or n+1 mean 0, 1 or n+2 mean   
   > 1, etc, and only have to reject values bigger than 2n+2.   
      
   Right.  In general if we want to get an unbiased uniform value in   
   some range, some results from rng() will have to be passed over   
   in cases where the number of possible values from calling rng()   
   is not an exact multiple of the number of values in the range   
   (which is n+1 in your example).  It's necessary to do something   
   along these general lines, as otherwise the results will be   
   biased in one direction or another.   
      
   > Also, do we   
   > have to select numbers in the range 0 to n and reject any duplicates,   
   > or can we rig things so we are selecting randomly only from those   
   > numbers not yet selected?   
      
   Either approach is valid as far as getting the right answer is   
   concerned.  You might prefer one of these methods over the other,   
   or perhaps yet a different method, considering some other aspect   
   of the problem, such as run-time performance or how much memory   
   is needed.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca