Re: bug in RandomChoice if weight is zero?
- To: mathgroup at smc.vnet.net
- Subject: [mg106037] Re: [mg105976] bug in RandomChoice if weight is zero?
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Thu, 31 Dec 2009 03:14:02 -0500 (EST)
- References: <200912290617.BAA02582@smc.vnet.net>
Matthias Greiff wrote:
> 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
I see your bug, and raise you another.
In[25]:= TimeConstrained[
RandomSample[UnitVector[100,1]->Range[100], 2], 10] (* hangs *)
Actually that's two more bugs, because it is both in some infinite
cycling and also not responding to aborts.
I'll look into repair today. Alternatively, I might go home and have a
good sob.
Daniel Lichtblau
Wolfram Research
- References:
- bug in RandomChoice if weight is zero?
- From: Matthias Greiff <greiff@mac.com>
- bug in RandomChoice if weight is zero?