MathGroup Archive 2001

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

Search the Archive

Re: Is this a bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32069] Re: Is this a bug?
  • From: atelesforos at hotmail.com (Orestis Vantzos)
  • Date: Sat, 22 Dec 2001 04:22:40 -0500 (EST)
  • References: <9vs8ph$g1d$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Your problem is with a[Random[Integer{0,1}]]++ :
It is interpreted as a[Random[Integer{0,1}]]=a[Random[Integer{0,1}]]+1
and therefore some of the times the loop transfers the value of one
register to the other (plus 1). In that case the combined value can
drop or rise by more than 1 -- hence you do not have a total sum of
50.
Mathematica is not C! Increment (++) has attribute HoldFirst,
therefore its argument (a[Random...] in this case) is evaluated ONLY
after arg++ has been replaced by arg=arg+1. Therefore this behaviour
is completely normal..
Orestis


  • Prev by Date: Re: NDSolve problem with piecewise functions
  • Next by Date: Re: Replacement Rule
  • Previous by thread: Re: Is this a bug?
  • Next by thread: Re: Re: Is this a bug?