MathGroup Archive 2000

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

Search the Archive

RE: need little help

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23557] RE: [mg23530] need little help
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Sat, 20 May 2000 03:10:32 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Wagner Truppel wrote:
--------------------
I have a list of probabilities (whose sum is 1.0), each associated with an
index. I'd like to randomly choose an index based on those probabilities.
For example, suppose m = {0.2, 0.4, 0.1, 0.3} 

----------------------
The following will work nicely.


In[1]:=
Roll:=With[{x=Random[]}, 
     Which[x<0.2,1,  x<0.6,2,  x<0.7,3,  True,4]
  ]


In[2]:=
Table[Roll,{15}]

Out[2]=
{4,2,2,2,4,4,1,1,4,2,2,4,2,3,4}


--------------------
Regards,
Ted Ersek

Mathematica tips, tricks are at
http://www.verbeia.com/mathematica/tips/Tricks.html



  • Prev by Date: Re: [Question] How to load(get) Packages
  • Next by Date: Question of function for hexahedron
  • Previous by thread: Re: need little help
  • Next by thread: Re: need little help