Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Monte-Carlo-methods/Ada/monte-carlo-methods.ada
Normal file
23
Task/Monte-Carlo-methods/Ada/monte-carlo-methods.ada
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
|
||||
|
||||
procedure Test_Monte_Carlo is
|
||||
Dice : Generator;
|
||||
|
||||
function Pi (Throws : Positive) return Float is
|
||||
Inside : Natural := 0;
|
||||
begin
|
||||
for Throw in 1..Throws loop
|
||||
if Random (Dice) ** 2 + Random (Dice) ** 2 <= 1.0 then
|
||||
Inside := Inside + 1;
|
||||
end if;
|
||||
end loop;
|
||||
return 4.0 * Float (Inside) / Float (Throws);
|
||||
end Pi;
|
||||
begin
|
||||
Put_Line (" 10_000:" & Float'Image (Pi ( 10_000)));
|
||||
Put_Line (" 100_000:" & Float'Image (Pi ( 100_000)));
|
||||
Put_Line (" 1_000_000:" & Float'Image (Pi ( 1_000_000)));
|
||||
Put_Line (" 10_000_000:" & Float'Image (Pi ( 10_000_000)));
|
||||
Put_Line ("100_000_000:" & Float'Image (Pi (100_000_000)));
|
||||
end Test_Monte_Carlo;
|
||||
Loading…
Add table
Add a link
Reference in a new issue