@flawr Going back to your approach: I think you need
-!A
rather than
=!a
. And you can use
Zr
(
randsample
) directly instead of
Z@
. So
Y@tG-!Af1ZrY)
works. I think it's worth posting noting that, unlike other answers, it doesn't use rejection sampling and its running time is deterministic :-)