MathGroup Archive 2005

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

Search the Archive

Re: For Loop and Array related

  • To: mathgroup at
  • Subject: [mg58022] Re: For Loop and Array related
  • From: "Garrett" <garrett.mitchener at>
  • Date: Thu, 16 Jun 2005 05:37:02 -0400 (EDT)
  • References: <d8oucl$t6q$>
  • Sender: owner-wri-mathgroup at

Try this:

For[i = 1, i <= 100, i++,
  n = Random[Integer, {1, 10}];
  Print[{n, Total[Lattice], Lattice}]]

Two things: It should be i <= 16000 (a comparison), not i = 16000 (an
assignment) in your For statement.

Also, after playing with this for a minute or two, I'm guessing that ++
is implemented internally as

expr = expr + 1

But Random is a non-referentially transparent operation: Imagine
expanding the ++ in your original form to ...

Lattice[[ Random[...] ]] = Lattice[[ Random[...] ]] + 1

and you can see that it replaces one random element of the lattice by
another random element plus one, hence the goofy behavior.  So to get
around this, you have to compute the random number and save it

Good luck,

-- Garrett Mitchener

  • Prev by Date: Re: Help with the User Interface in Mathematica 5.1.1
  • Next by Date: Re: Re: spotlight escape sequences
  • Previous by thread: Re: For Loop and Array related
  • Next by thread: Re: For Loop and Array related