B |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
Algorithm: Determine N Set Head = 0 LOOP from i=0 to N Generate a random number R from a uniform distribution Check IF R<0.5 THEN Increment Head by 1 END IF END LOOP OUTPUT N, Head, Head/N |
Output: N Head Head/N ------------- -------- --------- 10 4 0.4000000 100 41 0.4100000 1,000 466 0.4660000 10,000 5059 0.5059000 100,000 49942 0.4994200 1,000,000 500351 0.5003510 10,000,000 4998906 0.4998906 100,000,000 50006417 0.5000641 1,000,000,000 500008369 0.5000084 |