Random Numbers

Random Numbers

The next command produces a "random" real number between 0 and 1:

RandomReal[]

RandomReal[{-5,5}]

The next command produces a "random" integer 0 or 1:

RandomInteger[]

RandomInteger[{0,100}]

An Example: Monte-Carlo for π

s=SessionTime[];
pts=Table[{RandomReal[],RandomReal[]},{1000000}];
res=Map[Function[s,Floor[s[[1]]^2+s[[2]]^2]],pts];
4.(Length[res]-Apply[Plus,res])/Length[res]
Print[SessionTime[]-s," Seconds"]