       Re: problem with RandomInteger

• To: mathgroup at smc.vnet.net
• Subject: [mg112217] Re: problem with RandomInteger
• From: Peter Pein <petsie at dordos.net>
• Date: Sun, 5 Sep 2010 05:27:17 -0400 (EDT)
• References: <i5qhhg\$pkm\$1@smc.vnet.net>

```Am Sat, 4 Sep 2010 08:02:36 +0000 (UTC)
schrieb Albert Retey <awnl at gmx-topmail.de>:
...
> 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
>

Indeed! Using a compiled version of str1[], there is no chance to get
reliable results:

In:= strC = Compile[{}, Module[{l, i, j},
l = {0, 0, 0};
i = RandomInteger[{1, 3}];
l[[i]] = 1;
j = RandomInteger[{1, 3}];
l[[j]]], {{i | j, _Integer}, {l, _Integer, 1}}];

In:= N[Total[Table[strC[], {10}]]]/10

Out= 1.

In:= N[Total[Table[strC[], {1000}]]]/1000

Out= 1.

In:= N[Total[ParallelTable[strC[], {1000}]]]/1000

Out= 1.

But this gives the expected result:

In:=
simp=Compile[{{n,_Integer}},Sum[Boole[RandomInteger[{1,3}]===2],{n}]/n//N];
In:= simp/@(10^{1,2,3,4})
Out= {0.3,0.36,0.34,0.3386}

Can anyone from Wolfram Inc. please explain this behaviour?

TIA,
Peter

```

• Prev by Date: Problems with replacement rules inside functions
• Next by Date: NDSolve -- indexing of dependent variable that is arbitrary list
• Previous by thread: Re: problem with RandomInteger
• Next by thread: Re: problem with RandomInteger