Re: Assign a value to a variable
- To: mathgroup at smc.vnet.net
- Subject: [mg63009] Re: [mg62996] Assign a value to a variable
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 11 Dec 2005 04:56:32 -0500 (EST)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
Clear[a,b,c,d,e,f,g,h,i]; vars={a,b,c,d,e,f,g,h,i}; numbers=Range[9]; Set has attribute HoldFirst so that the LHS is not evaluated Attributes[Set] {HoldFirst,Protected,SequenceHold} Force evaluation of the LHS of Set rn= (Evaluate[vars[[ varsPos= Random[Integer,{1,Length[vars]}]]]]= numbers[[ Random[Integer,{1,Length[numbers]}]]]); {rn, varsPos,vars} {3,2,{a,3,c,d,e,f,g,h,i}} rn==vars[[varsPos]]== ToExpression[ FromCharacterCode[ ToCharacterCode["a"]+varsPos-1]] True Bob Hanlon > > From: Ben Becker <ben.becker at gmx.de> To: mathgroup at smc.vnet.net > Date: 2005/12/10 Sat AM 06:03:11 EST > Subject: [mg63009] [mg62996] Assign a value to a variable > > Hi! > > I have a list of variables: > vars = {a, b, c, d, e, f, g, h, i} > > and a list of numbers: > numbers = Range[9] > > Now i'd like to choose randomly a variable and a number. and then i'd > like to assign the number to the variable. > I thought of somehting like that: > > vars[[Random[Integer, {1, Length[vars]}]]] = > numbers[[Random[Integer, {1, Length[numbers]}]]] > > but it doesn't work. > > i hope you have an idea! > > thank you for answering! > > MFG Ben > >