MathGroup Archive 2005

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

Search the Archive

Re: Assign a value to a variable

  • To: mathgroup at
  • Subject: [mg63028] Re: Assign a value to a variable
  • From: "Tammo Jan Dijkema" <tammojan at>
  • Date: Sun, 11 Dec 2005 04:56:59 -0500 (EST)
  • References: <dnedkh$tf$>
  • Sender: owner-wri-mathgroup at

I think your code does work, however, it only assigns one value to one
variable. You would need to run through the entire list of variables to
get what you want. Note that it is not necessary to "shuffle" both left
and right hand side of the equals side. Here's a simple one-liner that
does the trick also:

Evaluate[Sort[vars, If[Random[] < 1/2, False] &]] = numbers;

The Sort function with the Random[] inside takes care of the shuffling.

Tammo Jan Dijkema

Ben Becker wrote:
> 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

  • Prev by Date: Re: A list of numbers without "73"
  • Next by Date: Re: functional programming
  • Previous by thread: Re: Assign a value to a variable
  • Next by thread: Re: Assign a value to a variable