MathGroup Archive 2010

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

Search the Archive

Re: problem with RandomInteger

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112222] Re: problem with RandomInteger
  • From: Themis Matsoukas <tmatsoukas at me.com>
  • Date: Sun, 5 Sep 2010 05:28:11 -0400 (EDT)

You are defining str1[] with an empty list of arguments. I don't see the purpose for that.  If you remove the [], then everything works fine:

str1 := Module[{l, i, j}, l = {0, 0, 0};
  i = RandomInteger[{1, 3}];
  l[[i]] = 1;
  j = RandomInteger[{1, 3}];
  l[[j]]]

n = 500;
N[Total[Table[str1, {n}]]]/n

0.324

Themis

PS: You may want to talk to someone at wolfram about this. As others pointed out, your initial code works if n<249 and breaks down if n is larger. I also noticed that if you remove l, i, j from the list of localized variables, your initial code works for any n. Wolfram may need to know about this inconsistent behavior. Nonetheless, I think that str1[] is not proper syntax in Mathematica and its possible that this behavior arises because mathematica does not anticipate an empty [].  Just hypothesizing here...

tm


  • Prev by Date: Re: problem with RandomInteger
  • Next by Date: Re: Question about ArrayFlatten
  • Previous by thread: Re: problem with RandomInteger
  • Next by thread: Re: problem with RandomInteger