Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,115 @@
with Ada.Text_Io;
with Ada.Numerics.Float_Random;
with Ada.Strings.Fixed;
procedure Modified_Distribution is
Observations : constant := 20_000;
Buckets : constant := 25;
Divider : constant := 12;
Char : constant Character := '*';
generic
with function Modifier (X : Float) return Float;
package Generic_Random is
function Random return Float;
end Generic_Random;
package body Generic_Random is
package Float_Random renames Ada.Numerics.Float_Random;
Generator : Float_Random.Generator;
function Random return Float is
Random_1 : Float;
Random_2 : Float;
begin
loop
Random_1 := Float_Random.Random (Generator);
Random_2 := Float_Random.Random (Generator);
if Random_2 < Modifier (Random_1) then
return Random_1;
end if;
end loop;
end Random;
begin
Float_Random.Reset (Generator);
end Generic_Random;
generic
Buckets : in Positive;
package Histograms is
type Bucket_Index is new Positive range 1 .. Buckets;
Bucket_Width : constant Float := 1.0 / Float (Buckets);
procedure Clean;
procedure Increment_Bucket (Observation : Float);
function Observations_In (Bucket : Bucket_Index) return Natural;
function To_Bucket (X : Float) return Bucket_Index;
function Range_Image (Bucket : Bucket_Index) return String;
end Histograms;
package body Histograms is
Hist : array (Bucket_Index) of Natural := (others => 0);
procedure Clean is
begin
Hist := (others => 0);
end Clean;
procedure Increment_Bucket (Observation : Float) is
Bin : constant Bucket_Index := To_Bucket (Observation);
begin
Hist (Bin) := Hist (Bin) + 1;
end Increment_Bucket;
function Observations_In (Bucket : Bucket_Index) return Natural
is (Hist (Bucket));
function To_Bucket (X : Float) return Bucket_Index
is (1 + Bucket_Index'Base (Float'Floor (X / Bucket_Width)));
function Range_Image (Bucket : Bucket_Index) return String is
package Float_Io is new Ada.Text_Io.Float_Io (Float);
Image : String := "F.FF..L.LL";
First : constant Float := Float (Bucket - 1) / Float (Buckets);
Last : constant Float := Float (Bucket - 1 + 1) / Float (Buckets);
begin
Float_Io.Put (Image (1 .. 4), First, Exp => 0, Aft => 2);
Float_Io.Put (Image (7 .. 10), Last, Exp => 0, Aft => 2);
return Image;
end Range_Image;
begin
Clean;
end Histograms;
function Modifier (X : Float) return Float
is (if X in Float'First .. 0.5
then 2.0 * (0.5 - X)
else 2.0 * (X - 0.5));
package Modified_Random is
new Generic_Random (Modifier => Modifier);
package Histogram_20 is
new Histograms (Buckets => Buckets);
function Column (Height : Natural; Char : Character) return String
renames Ada.Strings.Fixed."*";
use Ada.Text_Io;
begin
for N in 1 .. Observations loop
Histogram_20.Increment_Bucket (Modified_Random.Random);
end loop;
Put ("Range Observations: "); Put (Observations'Image);
Put (" Buckets: "); Put (Buckets'Image);
New_Line;
for I in Histogram_20.Bucket_Index'Range loop
Put (Histogram_20.Range_Image (I));
Put (" ");
Put (Column (Histogram_20.Observations_In (I) / Divider, Char));
New_Line;
end loop;
end Modified_Distribution;

View file

@ -19,7 +19,6 @@ nbins = 20
histsz = 200
binsz = 1 / nbins
len bins[] nbins
arrbase bins[] 0
#
for i to n
rn = rand

View file

@ -0,0 +1,83 @@
! Modified random distribution
! tested with Intel ifx (IFX) 2025.2.1 20250806 on Kubuntu 25.10
! GNU gfortran (Ubuntu 15.2.0-4ubuntu4) 15.2.0 on Kubuntu 25.10
! VSI Fortran x86-64 V8.7-001 on OpenVMS V9.2-3
! U.B., March 2026
!
program modrand
implicit none
integer, parameter :: DP=8 ! Reals hare Double PRecision here
integer, parameter :: NMAX=100000 ! Generate that many random numbers
integer, parameter :: nHist=21 ! Number of Histogram Channels
integer, parameter :: histMaxPoint = 80 ! Normalize maximum Histogram count to 80 chars width
real(kind=DP), dimension(0:nHist) :: HLimits ! the upper limit of each Histogram channel
integer, dimension(nHist) :: Hist ! THe histogram channels
integer :: ii, jj, ! loop indices
integer :: mv, nd ! maximum count in all histogram channels
real (kind=DP) :: r ! 1 generated random number
call random_seed () ! Initialize random number generator
do ii=0, nHist !Initialize Histogram limits
HLimits(ii) = real(ii,DP) / real(nHist, DP)
enddo
Hist = 0
do ii=1, NMAX ! Do the generation
call modifiedRandom (r)
do jj=1, nHist ! Find histogram channel
if (r .lt. HLimits (jj)) then
Hist(jj) = Hist(jj) + 1
exit
endif
end do
end do
! Display the histogram: Normalize such that maximum count would display as 80 '*'
mv = maxval(Hist)
write (*,'("---Range--- Count ")')
do ii=1, nHist
nd = histMaxPoint * real (hist(ii),DP) / real (mv ,DP) ! Number of stars to show
! Top line
write (*,'(F4.2,"...",F4.2,4X,I5,3x)',advance='no') HLimits(ii-1), HLimits(ii), hist(ii)
do jj=1,nd
write (*,'("*")', advance='no')
enddo
write (*,*)
enddo
write (*,'(/,"Total:", 7x,I7)') NMAX
contains
! =======================================================================
! returns r as modified randum value as described in the task description
! =======================================================================
subroutine modifiedRandom (r)
real(kind=DP), intent(out) :: r
real (kind=DP) :: r1, r2
r = -1._DP
do while (r .lt. 0._DP)
call random_number (r1)
call random_number (r2)
if (r2 < modifier(r1)) r = r1
end do
end subroutine modifiedRandom
! ======================================================
! The modifier function as shown in the task description
! ======================================================
pure function modifier(x) result (returnvalue)
real (kind=DP), intent(in) :: x
real (kind=DP) :: returnvalue
if (x .lt. 0.5_DP) then
returnvalue = 2.0_DP*(0.5_DP - x)
else
returnvalue = 2.0_DP*(x - 0.5_DP)
endif
end function modifier
end program modrand

View file

@ -0,0 +1,32 @@
require "table2"
local fmt = require "fmt"
local function rng(modifier)
while true do
local r1 = math.random()
local r2 = math.random()
if r2 < modifier(r1) then return r1 end
end
end
local modifier = |x| -> (x < 0.5) ? 2 * (0.5 - x) : 2 * (x - 0.5)
$define N = 100000
$define NUM_BINS = 20
$define HIST_CHAR = "■"
$define HIST_CHAR_SIZE = 125
local bins = table.rep(NUM_BINS, 0)
local bin_size = 1 / NUM_BINS
for i = 1, N do
local rn = rng(modifier)
local bn = rn // bin_size
bins[bn + 1] += 1
end
fmt.print($"Modified random distribution with %,s samples in range [0, 1):\n", N)
print(" Range Number of samples within that range")
for i = 0, NUM_BINS - 1 do
local hist = string.rep(HIST_CHAR, math.round(bins[i + 1] / HIST_CHAR_SIZE))
fmt.print("%4.2f ..< %4.2f %s %,s", bin_size * i, bin_size * (i + 1), hist, bins[i + 1])
end