last day (15 days later) » 

22:42
0
Q: To string or not to string

Flog EdocGiven an input string, output a random combination of any characters in the string, with an equal chance of each one occurring. Example: given the input abcd (or any combination thereof of the four characters a,b,c,d) , there is an equal chance of outputting: a b c d aa ab ac ad ba bb bc bd ca...

Welcome to PPCG!
@AdmBorkBork What's the difference?
Must we remove (some) characters with a 50% chance and then remove a uniform number of characters in [1,Length(string)], or are we free to use other distributions (so long as we do not always do the same thing with the same input)?
Can the removed characters be only contiguous, or must test be able to produce et?
@AdmBorkBork exactly, or you'll end up with pretty trivial answers like tio.run/…
22:42
The difference is that if we choose 0 as a random value of characters to remove it is indistinguishable from outputting the string as is.
@AdmBorkBork Hope the edit fixed this.
can a non-zero random number of chars be all chars, returning an empty string?
I think you mean the code should have a (equal?) chance of outputting any subsequence but the word "can" could easily (although probably incorrectly) be interpreted as "may".
In future, we have a sandbox to help refine challenges before they're posted. Random challenges are notoriously hard to phrase properly, so don't feel too bad about this one! It's an interesting challenge, it just needs a bit of help to get it to the finish line.
Re my "(equal?)" - see my Jelly answer - it has a chance to produce any of the subsequences (with a 50% chance of the unchanged string), but the distribution of the number of characters removed is, itself, not uniform but rather the distribution across subsequences is - is that acceptable or not?
22:42
@JonathanAllan Is it clearer now?
@Emigna I've modified it pretty much, so it's unlike what it was when some of the answers were posted, yeah.
If the input is "aab", do you want equal probabilities of outputting "aa" and "ab"? There is only one was of getting "aa" (remove the "b"), but two ways of getting "ab" (remove the first "a", or remove the second "a").
@RobinRyder Yes. You'd have the same chance of getting aa as you would ab in that case.
I hope it's more clearer now. I've illustrated that there is an equal chance of any possible valid combination.
How does starting with abcd then either (a) "removing characters" or (b) "replacing without removing any" result in aaa?
@JonathanAllan Clearer now?
@Emigna I've illustrated that now.
Hopefully there are no missing edge cases now that need to be covered, I hope.
So 'aaab', 'aabb' and 'abbb' would yield the same list of equally possible results?
22:42
@gwaugh Yes, that is indeed the case.
Nominated to reopen and updated my answer.
Thanks!
There are a couple other questions in the Sandbox I could use some constructive feedback about: https://codegolf.meta.stackexchange.com/questions/2140/sandbox-for-proposed-challenges/17538#17538

https://codegolf.meta.stackexchange.com/questions/2140/sandbox-for-proposed-challenges/17520#17520

last day (15 days later) »