Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

RandomChoice does not accept null weights

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83403] RandomChoice does not accept null weights
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 19 Nov 2007 06:21:15 -0500 (EST)

RandomChoice does not accept 0 weights.

Example:

In[1]:= RandomChoice[{0,1,2}->{a,b,c}]

During evaluation of In[1]:= RandomChoice::weightv: The weights given on 
the left-hand side of {0,1,2}->{a,b,c} should be a list of positive 
numerical quantities having the same length as the list given on the 
right-hand side. >>

Out[1]= RandomChoice[{0,1,2}->{a,b,c}]

Is this the intended behaviour?

Of course it is very easy to work around this problem by either adding a 
very small number to all weights, or Pick[]ing out those elements whose 
weight is not 0 before passing them to RandomChoice[].

But in many situations it would be very useful if RandomChoice accepted 
0 as a weight ...

Szabolcs


  • Prev by Date: Plotting Points with Labels
  • Next by Date: Re: classes.m
  • Previous by thread: Re: RandomChoice does not accept null weights
  • Next by thread: Re: RandomChoice does not accept null weights