MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

bug in RandomChoice if weight is zero?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105976] bug in RandomChoice if weight is zero?
  • From: Matthias Greiff <greiff at mac.com>
  • Date: Tue, 29 Dec 2009 01:17:27 -0500 (EST)

If I use RandomChoice with weights of zero the corresponding elements will never be selected.

In[62]:= RandomChoice[{0, 0, 3} -> {3, 2, 1}, 5]
Out[62]= {1, 1, 1, 1, 1}

Why is it not the same if I use RandomSample?
The following command

RandomSample[{1, 2, 0} -> Range[3], 2]

returns either {1,2} or {2,1}. But when I change the command to sample size 3  I get the following.

In[60]:= RandomSample[{1, 2, 0} -> Range[3], 3]
Out[60]= {2, 1, 3}

Why is the third element selected? Shouldn't Mathematica return an error message because the sample size is larger than the population size?

Appreciate your answers. 

Merry Christmas!

Matthias


  • Prev by Date: Re: Re: Replace and ReplaceAll -- simple application
  • Next by Date: Re: Re[] function
  • Previous by thread: NASTY INTEGRAL. need advice
  • Next by thread: Re: bug in RandomChoice if weight is zero?