MathGroup Archive 2009

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

Search the Archive

Re: bug in RandomChoice if weight is zero?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106025] Re: bug in RandomChoice if weight is zero?
  • From: dh <dh at metrohm.com>
  • Date: Wed, 30 Dec 2009 04:16:58 -0500 (EST)
  • References: <hhc72h$2k5$1@smc.vnet.net>

Hi Mathias,
from the manual:
"RandomSample[{Subscript[e, 1],Subscript[e, 2],\[Ellipsis]},n] never
samples any of the Subscript[e, i] more than once."
Daniel

On 29 Dez., 07:20, Matthias Greiff <gre... at mac.com> 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



  • Prev by Date: Re: Re: Re: Replace and ReplaceAll -- simple application
  • Next by Date: Re: Return in function
  • Previous by thread: Re: Re: bug in RandomChoice if weight is zero?
  • Next by thread: Re: Re: bug in RandomChoice if weight is zero?