20
1
Create a program that outputs itself.
However, if the source code is repeated n times (meaning to concatenate a copy of the source code to the end n-1 times), then there should be 1/n probability outputting the original source code, a 1/n probability of outputting the source code repeated twice, a 1/n probability of outputting the source code repeated three times, ..., and a 1/n probability of outputting the source code n times.
For example, if your program is foobar, then it should always output exactly foobar.
However, if you run foobarfoobarfoobarfoobar, then there should be a ¼ chance each of outputting foobar, foobarfoobar, foobarfoobarfoobar and foobarfoobarfoobarfoobar.
- The distribution of each possible output should be equal
- In addition to standard I/O methods applying and standard loopholes forbidden, standard quine rules apply (can't access its own source, etc.)
- This is code golf so shortest answer in bytes wins
Is pseudorandom good enough? – wastl – 7 years ago
1@wastl Yep, that's alright – JMigst – 7 years ago
2Your definition is slightly off. If you repeat it 1 time (i.e.
foobarfoobar) then it'd only printfoobar– Veskah – 7 years ago1@Veskah
foobarfoobarisfoobarrepeated two times, not once. – Nit – 7 years ago@Nit You start with the source. If you use it again, you have only repeated it once but have two instances. – Veskah – 7 years ago
@Veskah I'd say this is just not how the phrase works, but "by concatenating a copy of the source code to the end n times" seems to imply what you say. However, then the probabilities don't add up to 1. – Ørjan Johansen – 7 years ago
Yeah, I'll clear up the ambiguity. I would agree for repeating 3 times would be
foobarfoobarfoobarbut that would be inconsistent – JMigst – 7 years ago