# ================================================================
begin {
  if (isabsent(@olen)) {
    @olen = 16;
  }
  if (isabsent(@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;
  }
}
