Skip to main content
Tweeted twitter.com/#!/StackMma/status/378356983117922304
Made title and tagging more general
Link
István Zachar
  • 47.2k
  • 20
  • 147
  • 307

Is it possible to use RandomChoice to choose decrements or increments in variableswithout other choices being evaluated?

Source Link
Red Banana
  • 5.6k
  • 3
  • 31
  • 49

Is it possible to use RandomChoice to choose decrements or increments in variables?

I'm trying to do this:

i1 = 1;
i2 = 1;

RandomChoice[{
  (i1 = i1 + 1),
  (i1 = i1 - 1),
  (i2 = i1 + 1),
  (i2 = i2 - 1)}]

In order to chose randomly which variable is going to be incremented or decremented - but it's not working. I've also tried with -- and ++ but I had the same problem. I am clueless about what may be the problem.