Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,32 @@
func$ rep c$ n .
for i to n : r$ &= c$
return r$
.
func modifier x .
if x < 0.5 : return 2 * (0.5 - x)
return 2 * (x - 0.5)
.
func rand .
repeat
r1 = randomf
r2 = randomf
until r2 < modifier r1
.
return r1
.
n = 100000
nbins = 20
histsz = 200
binsz = 1 / nbins
len bins[] nbins
arrbase bins[] 0
#
for i to n
rn = rand
bn = floor (rn / binsz)
bins[bn] += 1
.
numfmt 0 4
for i range0 nbins
print bins[i] & " " & rep "*" (bins[i] / histsz)
.

View file

@ -0,0 +1,34 @@
module Modified_random_distribution (f, m, bins){
form 60, 32
Cls 1, 0
Report "Modified Random Distribution"
Cls 0, 1
Cursor 0, 5
T$="Range Istogram"
Print #f, T$
Print T$
double a[bins]
def modifier(x) = if(x < 0.5-> 1-2*x, 2*x -1)
for i=1 to m
while True:
random1 = rnd
random2 = rnd
if random2 < modifier(random1) then
answer = int(random1*bins)
a[answer]++
exit
end if
end while
next
b=100 / bins
for i=0 to bins-1
L$=format$("{0:1:-4} - {1:1:-4} {2} {3}% ",i*b,(i+1)*b-.1, string$("*",a[i]/(m/bins)*20), round(a[i]/m*100,2))
Print #f, L$
Print L$
next
}
// Ansi file / use for wide output for UTF16LE
Open "ModRandomDistr.txt" for output as #f
Modified_random_distribution f, 10000, 21
close #f

View file

@ -0,0 +1,21 @@
function modifier(x: real) := if x < 0.5 then 2 * (0.5 - x) else 2 * (x - 0.5);
function modrand(modifier: real-> real): sequence of real;
begin
repeat
var r := Random;
if Random < modifier(r) then yield r;
until false;
end;
begin
var data := modrand(modifier).Take(100_000);
var bins := data.Select(x -> (20 * x).Floor)
.Sorted
.GroupBy(n -> n)
.Select(g -> g.Count);
writeln('Bin Counts Histogram');
foreach var counts in bins index i do
writeln(i / 20:2:2, counts:6, ': ', '■' * (counts div 125));
end.