C, 585 611 615 623 673 707 bytes
Source code:
j,c,p[256][256]={0},r;char*a,*b,*y,Y[999],*X="j,c,p[256][256]={0},r;char*a,*b,*y,Y[999],*X=\"@\";main(){a=b=X;for(y=Y;*a-64;)*y++=*a++;for(;*b;*y++=*b++)if(*b==34)*y++=92;for(a++;*a;)*y++=*a++;*y=0;for(;Y-y--;)p[c=*y][*(y+1)]++;while(c){putchar(c);for(r=j=0;j<256;j++)r+=p[c][j];r=rand()%r;for(j=0;j<256;j++){r-=p[c][j];if(r<0)break;}c=j;}}";main(){a=b=X;for(y=Y;*a-64;)*y++=*a++;for(;*b;*y++=*b++)if(*b==34)*y++=92;for(a++;*a;)*y++=*a++;*y=0;for(;Y-y--;)p[c=*y][*(y+1)]++;while(c){putchar(c);for(r=j=0;j<256;j++)r+=p[c][j];r=rand()%r;for(j=0;j<256;j++){r-=p[c][j];if(r<0)break;}c=j;}}
With newlines and whitespace added for legibility/explanation:
01 j,c,p[256][256]={0},r;
02 char*a,*b,*y,Y[999],*X="j,c,p[256][256]={0},r;char*a,*b,*y,Y[999],*X=\"@\";main(){a=b=X;for(y=Y;*a-64;)*y++=*a++;for(;*b;*y++=*b++)if(*b==34)*y++=92;for(a++;*a;)*y++=*a++;*y=0;for(;Y-y--;)p[c=*y][*(y+1)]++;while(c){putchar(c);for(r=j=0;j<256;j++)r+=p[c][j];r=rand()%r;for(j=0;j<256;j++){r-=p[c][j];if(r<0)break;}c=j;}}";
03 main(){
04 a=b=X;
05 for(y=Y;*a-64;) *y++=*a++;
06 for(;*b;*y++=*b++) if(*b==34) *y++=92;
07 for(a++;*a;) *y++=*a++;
08 *y=0;
09 for(;Y-y--;) p[c=*y][*(y+1)]++;
10 while(c){
11 putchar(c);
12 for(r=j=0;j<256;j++) r+=p[c][j];
13 r=rand()%r;
14 for(j=0;j<256;j++){
15 r-=p[c][j];
16 if(r<0) break;
17 }
18 c=j;
19 }
20 }
The variable p[][]
will contain the occurrences of each character following another. X
contains the entire source, with '@'
substituted for the value of X
, in quotes.
The for-loops on lines 05
, 06
, and 07
replace the '@'
in X
with the content of X
, escaping double quotes, and stores it in Y
.
Line 09
tallies the occurrences of one character following another and starts the Markov model at the first character of the program ('j'
).
The while loop from 10
to 19
first outputs the current state of the Markov model, then finds the next state using a random number within the range of all successive occurrences.
Sample output:
j;Y[256;ma=";f(r(j<256]=r(y]++++){a+;*()*b=p[c],p[chile(j,*y+++++=0;fora=p[j=Y-;f()*a+;){an(ak;Y;j],p[c][c=99][256;for=*a=r;j=*a;*ar;for(y-----y=34)%r()p[256][*a+)*y][99][c=*b;for+)*(r(y+=*y+;for=0;forea+=0;f(c)if(r;*(;}"j<256];fore(y++=*y-y+;f(j++)ifor(;*a+;c];*y++++)*b=*a-;for*ak;*y+1)*br(c)*y+)*y=0;for<256][j][2564;f(r+="@\"j<256;*ar<0;Y[c];j+=p[c)r(y],*a,r(r==*X;ma-6]+++;}