MathGroup Archive 2005

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

Search the Archive

Re: Assign a value to a variable


Ben Becker schrieb:
> 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
> 
Hello,

Set[vars[[Random[Integer, {1, Length[vars]}]]],
  numbers[[Random[Integer, {1, Length[numbers]}]]]];
vars
--> {a, b, c, d, e, f, 3, h, i}

Peter


  • Prev by Date: Re: How to hide a cell?
  • Next by Date: Re: Assign a value to a variable
  • Previous by thread: Assign a value to a variable
  • Next by thread: Re: Assign a value to a variable