# Output: a prn in range(0;$n) where $n is `.` def prn: if . == 1 then 0 else . as $n | ([1, (($n-1)|tostring|length)]|max) as $w | [limit($w; inputs)] | join("") | tonumber | if . < $n then . else ($n | prn) end end; # An illustration - 10 selections at random with replacement: range(0;10) | ["a", "b", "c"] | .[length|prn]