Re: python & mathematical methods of picking numbers at random

From: Samuel Walters (swalters_usenet_at_yahoo.com)
Date: 01/16/04


Date: Fri, 16 Jan 2004 04:47:09 GMT


| Bart Nessux said |

> I am using method 'a' below to pick 25 names from a pool of 225. A
> co-worker is using method 'b' by running it 25 times and throwing out the
> winning name (names are associated with numbers) after each run and then
> re-counting the list and doing it all over again.
>
> My boss thinks that 'b' is somehow less fair than 'a', but the only thing
> I see wrong with it is that it is really inefficient and ugly as it's
> doing manually what 'a' does automatically, other than that I think the
> outcome of both methods (25 unique winners from a pool of 225) are the
> same. Anyone disagree with that and if so, please demonstrate how 'b'
> isn't as fair as 'a'
>
> count = len(list_of_potential_winners)
>
> a = random.sample(range(count), 25)
>
> b = random.sample(range(count), 1)
>
> Thanks!
> Bart

I looked at the code for random.sample, and found out that the two methods
are probabilistically equivalent. Neither is more or less fair than the
other.

You can, however, poke fun at your cow-orker for using
random.sample(range(count, 1) when random.randint(1,count) would have done
the exact same thing with the way he used random.sample.

HTH

Sam Walters.

P.S. The code for sample in random.py is very simple and fairly
straightforward. You should take a peek at it. The basic algorithm is to
make a list of winners, choose a random number, then if the winner is not
already in the list, add them. If the winner is already in the list,
retry until a new winner comes up. Repeat until you have the desired
number of winners.

-- 
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
    Do you really want to go there?"""


Relevant Pages

  • Re: Armstrong the greatest?
    ... "winning" an inning in the World Series. ... that competition the "Intermediate Time Trial Time Split" winner. ... Drew Carey will never win the Tour - he keeps diluting the team goal with all ... Cycling is the only professional sport where teams show up to the biggest events ...
    (rec.bicycles.racing)
  • Re: Armstrong the greatest?
    ... "winning" an inning in the World Series. ... that competition the "Intermediate Time Trial Time Split" winner. ... Drew Carey will never win the Tour - he keeps diluting the team goal with all ... Cycling is the only professional sport where teams show up to the biggest events ...
    (rec.bicycles.racing)
  • PRIZE AWARDS WINNING NOTIFICATION
    ... FROM:GOVERNMENT ACCREDITED LICENSED LOTTERY PROMOTERS. ... WINNING NOTICE FOR CATEGORY "A" WINNER ... RE:BONUS LOTTERY PROMOTION PRIZE AWARDS WINNING NOTIFICATION ... Your prize awards has been insured with your e-mail address and will be transfered to you upon meeting our requirements, statutory obligations, verifications, validations and satisfactory report. ...
    (Linux-Kernel)
  • Re: python & mathematical methods of picking numbers at random
    ... Bart Nessux writes: ... > the winning name after each run ... > and then re-counting the list and doing it all over again. ... for a big lottery or something) then you should use a better RNG. ...
    (comp.lang.python)
  • Re: Northern Ireland bans kids mini-rugby tournaments
    ... "Winning is a huge part of any sporting tournament. ... because they don't want any club to end up as the ultimate winner. ... they want rugby to be about fun, including as many kids as possible in the ... However they WON'T be able to play ...
    (rec.sport.rugby.union)