Given an input string
S followed by a non-empty separator in the following way:
1/2chance of being printed, and a
1/2chance for the program to terminate.
2/3chance of being printed, and a
1/3chance for the program to terminate.
3/4chance of being printed, and a
1/4chance for the program to terminate.
n/(n+1)chance of being printed, and a
1/(n+1)chance for the program to terminate.
The input string will only consist of characters that are acceptable in your language's string type.
Any non-empty separator can be used, as long as it is always the same. It is expected that the separator is printed after the last print of
Sbefore the program terminates.
The program has a
1/2chance of terminating before printing anything.
A trailing new line is acceptable.
Your answer must make a genuine attempt at respecting the probabilities described. Obviously, when
nis big this will be less and less true. A proper explanation of how probabilities are computed in your answer (and why they respect the specs, disregarding pseudo-randomness and big numbers problems) is sufficient.
This is code-golf, so the shortest answer in bytes wins.