Re: problem with RandomInteger
- To: mathgroup at smc.vnet.net
- Subject: [mg112206] Re: problem with RandomInteger
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Sat, 4 Sep 2010 04:02:46 -0400 (EDT)
- References: <i5qhhg$pkm$1@smc.vnet.net>
Am 03.09.2010 12:09, schrieb Yuri Izrailsky: > Hello Mathgroup, > > I have recently encountered a strange behavior of RandomInteger > function when used inside Module construct. Here is an example: > > str1[] := Module[{l, i, j}, > l = {0, 0, 0}; > i = RandomInteger[{1, 3}]; > l[[i]] = 1; > j = RandomInteger[{1, 3}]; > l[[j]] > ] > > In[3]:= N[Total[Table[str1[],{200}]]]/200 > Out[3]= 0.345 > > which is reasonably close to 1/3, but > > In[5]:= N[Total[Table[str1[],{1000}]]]/1000 > Out[5]= 0.997 > > looks very strange. What's happening here? I think this is because Table does compile if it thinks that will improve speed. You can change the limit when this will start, e.g.: SetSystemOptions["CompileOptions" -> "TableCompileLength" -> 100000]; now N[Total[Table[str1[], {10000}]]]/10000 will return the expected result. I don't exactly understand why this goes wrong when compiling, but I think it is a bug... hth, albert