New in Wolfram
Mathematica
8: Compiler Performance Enhancements
◄
previous
|
next
►
Software Development
Random Number Generation
The
Mathematica
Compile
statement now supports random number generation.
In[1]:=
X
n = 1000000; incircle = Compile[{}, With[{pt = {RandomReal[], RandomReal[]}}, If[Norm[pt] < 1, 1, 0]]];
In[2]:=
X
4.0*Total[Table[incircle[], {n}]]/n
Out[2]=
In[3]:=
X
n = 5000; randpt = Compile[{}, With[{pt = {RandomReal[], RandomReal[]}}, pt]];
In[4]:=
X
Graphics[{If[Norm[#] < 1, Red, Blue], Point[#]} & /@ Table[randpt[], {n}]]
Out[4]=