MathGroup Archive 2007

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

Search the Archive

Re: Beginner--Help on Listing Values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74933] Re: [mg74919] Beginner--Help on Listing Values
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 12 Apr 2007 04:45:14 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

randomList[n_Integer]:=
    Module[{t=Table[Random[],{n}]},
      t=t/Total[t];
      ReplacePart[t, 1-Total[Most[t]], -1]];

test=randomList[5]

{0.115755,0.0666108,0.278959,0.187075,0.3516}

Total[test]//InputForm

1.


Bob Hanlon

---- m.lungay at gmail.com wrote: 
> I need to create a list of probability values for a certain random variable X. It is very difficult if i keep on enumerating the entries especially when the length required is large, say the list is of length 100. Maybe there is some way where I could generate the entries in a random manner. There is a code Random[], but how could I implement it in a List manner so that the sum of the results must be 1. Please help!
> 
>  
> 
> Link to the forum page for this post:
> http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Special:Forum_ViewTopic&pid=17333#p17333
> Posted through http://www.mathematica-users.org [[postId=17333]]
> 


  • Prev by Date: Re: Beginner--Help on Listing Values
  • Next by Date: Re: bug in Integrate (5.2)
  • Previous by thread: Re: Beginner--Help on Listing Values
  • Next by thread: Re: Beginner--Help on Listing Values