Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,10 +0,0 @@
package Random_57 is
type Mod_7 is mod 7;
function Random7 return Mod_7;
-- a "fast" implementation, minimazing the calls to the Random5 generator
function Simple_Random7 return Mod_7;
-- a simple implementation
end Random_57;

View file

@ -1,57 +0,0 @@
with Ada.Numerics.Discrete_Random;
package body Random_57 is
type M5 is mod 5;
package Rand_5 is new Ada.Numerics.Discrete_Random(M5);
Gen: Rand_5.Generator;
function Random7 return Mod_7 is
N: Natural;
begin
loop
N := Integer(Rand_5.Random(Gen))* 5 + Integer(Rand_5.Random(Gen));
-- N is uniformly distributed in 0 .. 24
if N < 21 then
return Mod_7(N/3);
else -- (N-21) is in 0 .. 3
N := (N-21) * 5 + Integer(Rand_5.Random(Gen)); -- N is in 0 .. 19
if N < 14 then
return Mod_7(N / 2);
else -- (N-14) is in 0 .. 5
N := (N-14) * 5 + Integer(Rand_5.Random(Gen)); -- N is in 0 .. 29
if N < 28 then
return Mod_7(N/4);
else -- (N-28) is in 0 .. 1
N := (N-28) * 5 + Integer(Rand_5.Random(Gen)); -- 0 .. 9
if N < 7 then
return Mod_7(N);
else -- (N-7) is in 0, 1, 2
N := (N-7)* 5 + Integer(Rand_5.Random(Gen)); -- 0 .. 14
if N < 14 then
return Mod_7(N/2);
else -- (N-14) is 0. This is not useful for us!
null;
end if;
end if;
end if;
end if;
end if;
end loop;
end Random7;
function Simple_Random7 return Mod_7 is
N: Natural :=
Integer(Rand_5.Random(Gen))* 5 + Integer(Rand_5.Random(Gen));
-- N is uniformly distributed in 0 .. 24
begin
while N > 20 loop
N := Integer(Rand_5.Random(Gen))* 5 + Integer(Rand_5.Random(Gen));
end loop; -- Now I <= 20
return Mod_7(N / 3);
end Simple_Random7;
begin
Rand_5.Reset(Gen);
end Random_57;

View file

@ -1,51 +0,0 @@
with Ada.Text_IO, Random_57;
procedure R57 is
use Random_57;
type Fun is access function return Mod_7;
function Rand return Mod_7 renames Random_57.Random7;
-- change this to "... renames Random_57.Simple_Random;" if you like
procedure Test(Sample_Size: Positive; Rand: Fun; Precision: Float := 0.3) is
Counter: array(Mod_7) of Natural := (others => 0);
Expected: Natural := Sample_Size/7;
Small: Mod_7 := Mod_7'First;
Large: Mod_7 := Mod_7'First;
Result: Mod_7;
begin
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line("Sample Size: " & Integer'Image(Sample_Size));
Ada.Text_IO.Put( " Bins:");
for I in 1 .. Sample_Size loop
Result := Rand.all;
Counter(Result) := Counter(Result) + 1;
end loop;
for J in Mod_7 loop
Ada.Text_IO.Put(Integer'Image(Counter(J)));
if Counter(J) < Counter(Small) then Small := J; end if;
if Counter(J) > Counter(Large) then Large := J; end if;
end loop;
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line(" Small Bin:" & Integer'Image(Counter(Small)));
Ada.Text_IO.Put_Line(" Large Bin: " & Integer'Image(Counter(Large)));
if Float(Counter(Small)*7) * (1.0+Precision) < Float(Sample_Size) then
Ada.Text_IO.Put_Line("Failed! Small too small!");
elsif Float(Counter(Large)*7) * (1.0-Precision) > Float(Sample_Size) then
Ada.Text_IO.Put_Line("Failed! Large too large!");
else
Ada.Text_IO.Put_Line("Passed");
end if;
end Test;
begin
Test( 10_000, Rand'Access, 0.08);
Test( 100_000, Rand'Access, 0.04);
Test( 1_000_000, Rand'Access, 0.02);
Test(10_000_000, Rand'Access, 0.01);
end R57;

View file

@ -1,13 +0,0 @@
Option Explicit
function dice5
dice5 = int(rnd*5) + 1
end function
function dice7
dim j
do
j = 5 * dice5 + dice5 - 6
loop until j < 21
dice7 = j mod 7 + 1
end function