RosettaCodeData/Task/Monte-Carlo-methods/AWK/monte-carlo-methods.awk

11 lines
193 B
Awk
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
# --- with command line argument "throws" ---
BEGIN{ th=ARGV[1];
2014-01-17 05:32:22 +00:00
for(i=0; i<th; i++) cin += (rand()^2 + rand()^2) < 1
printf("Pi = %8.5f\n",4*cin/th)
2013-04-10 21:29:02 -07:00
}
usage: awk -f pi 2300
Pi = 3.14333