MathGroup Archive 2010

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

Search the Archive

Re: bug in RandomChoice if weight is zero?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106198] Re: bug in RandomChoice if weight is zero?
  • From: Matthias <greiff at mac.com>
  • Date: Tue, 5 Jan 2010 01:42:47 -0500 (EST)
  • References: <200912290617.BAA02582@smc.vnet.net> <hhhmsp$og2$1@smc.vnet.net>

Another interesting thing about RandomSample is the following:

In[171]:= RandomSample[{0, 0, 0, 1, 0} -> {1, 2, 3, 4, 5}, 1]
RandomSample[{0, 0, 0, 1, 0} -> {1, 2, 3, 4, 5}, 2]
RandomSample[{0, 0, 0, 1, 0} -> {1, 2, 3, 4, 5}, 3]
RandomSample[{0, 0, 0, 1, 0} -> {1, 2, 3, 4, 5}, 5]

Out[171]= {4}
Out[172]= {4, 5}
Out[173]= {4, 5, 5}
Out[174]= {4, 5, 5, 5, 5}

Although the fifth element has weight zero it is selected multiple
times? Is that only in my version of Mathematica (Version 7.0.1.0 on
Max OS X 10.6.2)?

Of course there are ways to work around that but, as DrMajorBob,
already pointed out, this contradicts the documentation.


  • Prev by Date: Re: Wrong ODE solution in Mathematica 7?
  • Next by Date: Re: NDSolve problem with switching equations
  • Previous by thread: Re: RSolve problem: won't solve convolution recurrence relation.
  • Next by thread: FullForm puzzle.