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 – 2018-05-22T22:10:00.280
1@wastl Yep, that's alright – JMigst – 2018-05-22T22:31:12.077
2Your definition is slightly off. If you repeat it 1 time (i.e.
foobarfoobar
) then it'd only printfoobar
– Veskah – 2018-05-23T02:34:05.8471@Veskah
foobarfoobar
isfoobar
repeated two times, not once. – Nit – 2018-05-23T08:25:04.773@Nit You start with the source. If you use it again, you have only repeated it once but have two instances. – Veskah – 2018-05-23T22:16:31.280
@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 – 2018-05-24T01:21:35.087
Yeah, I'll clear up the ambiguity. I would agree for repeating 3 times would be
foobarfoobarfoobar
but that would be inconsistent – JMigst – 2018-05-24T03:25:19.910