MathGroup Archive 2005

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

Search the Archive

Re: Assign a value to a variable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63021] Re: Assign a value to a variable
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sun, 11 Dec 2005 04:56:43 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 12/10/05 at 6:03 AM, ben.becker at gmx.de (Ben Becker) wrote:

>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.

In[52]:=
Set[#,numbers[[Random[Integer,{1,9}]]]]&/@vars;
vars

Out[53]=
{2,2,9,1,7,6,5,1,5}

Note, this will not work when a, b, c ... have already been assigned values. Nor does it prevent two of your variables from being assigned the same value.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Skewness problem
  • Next by Date: Re: UML-like diagrams for Mathematica
  • Previous by thread: Re: Assign a value to a variable
  • Next by thread: Re: Assign a value to a variable