mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-23 16:08:43 +00:00
39 lines
863 B
Text
Executable file
39 lines
863 B
Text
Executable file
# ================================================================
|
|
begin {
|
|
if (is_absent(@olen)) {
|
|
@olen = 16;
|
|
}
|
|
if (is_absent(@ocount)) {
|
|
@ocount = 16;
|
|
}
|
|
}
|
|
|
|
# ================================================================
|
|
for (_, v in $*) {
|
|
if (string(v) == "inf" || string(v) == "nan") {
|
|
continue;
|
|
}
|
|
int n = strlen(v);
|
|
for (int i = 0; i < n; i += 1) {
|
|
str a = substr(v, i, i);
|
|
@a_histo[a] += 1;
|
|
}
|
|
}
|
|
|
|
# ================================================================
|
|
end {
|
|
# Define this in this scope else it'll be scoped to the for-loop.
|
|
map a_cmf = compute_cmf_from_histo(@a_histo);
|
|
|
|
for (int oi = 0; oi < @ocount; oi += 1) {
|
|
str out = "";
|
|
for (int i = 0; i < @olen; i += 1) {
|
|
str oa = sample_from_cmf(a_cmf);
|
|
if (oa == "") {
|
|
break;
|
|
}
|
|
out .= oa;
|
|
}
|
|
print out;
|
|
}
|
|
}
|