Faux Source Code

23

2

Output one random character for each character of source code (as illustrated below). The probability of each character is its frequency in the original source code. Thus the output will be fake source code resembling a quine.

Specification

  • Restrictions
    • Standard constrains apply. No empty programs or functions. Also no reading your own source.
  • Output
    • The number of characters output should be exactly the number of characters in the source code
    • Each output character should be randomly choosen
    • The probability of choosing any character is equal to (occurrences in source) / (length of source)
    • This means that even a unary solution needs to 'randomly' choose 1 with probability 1. Which is to say that the output can't be hard coded.
  • Winning
    • This is code golf, so fewest bytes wins

Example

Program           Frequency           Probability           Possible Output
-------           ---------           -----------           ---------------           
 a@!@              a - 1               a - 25%               @@a@
                   ! - 1               ! - 25%
                   @ - 2               @ - 50%
Program           Frequency           Probability           Possible Output
-------           ---------           -----------           ---------------
caBaDBcDaBDB       a - 3               a - 25%               aaaBBBBccDDD
                   B - 4               B - 33%
                   c - 2               c - 17%
                   D - 3               D - 25%

NonlinearFruit

Posted 2016-09-07T21:44:43.027

Reputation: 5 334

Are single-character quines allowed? – Nathan Merrill – 2016-09-07T21:59:04.663

@NathanMerrill Yes, single character (and other unary) solutions are allowed. However, their output still needs to be randomly chosen. – NonlinearFruit – 2016-09-07T22:03:23.270

How shall I find the occurences of characters in a file if I am not allowed to read it? – Titus – 2016-09-07T22:38:07.663

That is the quine part. Usually quines have the actual source code and a string that contains a copy of the source code. Here is a Python quine _='_=%r;print _%%_';print _%_ – NonlinearFruit – 2016-09-07T22:47:12.953

Yup, I got it from the Jelly explanation. thanks. – Titus – 2016-09-07T22:57:47.630

@NonlinearFruit my program "randomly" chooses the letter s from the set of letters "s" it is truly random too! – Rohan Jhunjhunwala – 2016-09-07T23:12:18.007

1Is this [tag:code-golf]? – OldBunny2800 – 2016-09-07T23:54:45.913

@OldBunny2800 Good catch! I forgot the winning criterion (-‸ლ) – NonlinearFruit – 2016-09-08T00:00:08.343

@RohanJhunjhunwala That is a bit of a loophole. In the Specification, I was trying to outlaw solutions like that. I'm sorry if it wasn't clear. Which is to say that the output can't be hard coded. – NonlinearFruit – 2016-09-08T00:05:10.820

@NonlinearFruit so are unary quine answers unacceptable? – Rohan Jhunjhunwala – 2016-09-08T00:07:52.863

@RohanJhunjhunwala Unary solutions are welcome, that is why I chose the wording I used. But they have to conform (like everyone else) to the random criterion. Printing s and choosing s randomly from a one element set have the same result but are semantically different. This is a little nit-picky, but without it some solutions could curtail the gist of this challenge.

– NonlinearFruit – 2016-09-08T00:55:11.197

Is it mistake in the first example output? @@a@ should be @@a!? – VolAnd – 2016-09-08T05:25:46.103

1@VolAnd No. The probability of each character appearing is based on the character frequency. If you flip a coin twice and it lands on heads once, it doesn't have to hand on tails the second time. – wizzwizz4 – 2016-09-08T06:29:23.840

@wizzwizz4 I understand, it was necessary to use a random number to generate output – VolAnd – 2016-09-08T06:55:52.717

Is it ok to generate a random permutation of the source? – Adám – 2016-09-08T19:01:13.110

@Adam No, each output character should be chosen independently of the other output characters – NonlinearFruit – 2016-09-08T19:08:20.227

Answers

8

CJam, 14 bytes

{{E*`mR}`mR}E*

Try it online!

Explanation

Each character appears exactly twice, so the probabilities of the characters should all be the same.

{           e# Repeat this block 14 times.
  {E*`mR}   e# Push this (nonsensical) block.
  `         e# Stringify it, giving the string "{E*`mR}", which contains each of the
            e# seven characters once.
  mR        e# Select one of the characters at random.
}E*

Martin Ender

Posted 2016-09-07T21:44:43.027

Reputation: 184 808

7

Jelly, 13 bytes

“;⁾vṾWṁ$X€”vṾ

Try it online!

How it works

“;⁾vṾWṁ$X€”vṾ  Main link. No arguments.

“;⁾vṾWṁ$X€”    Set the argument and return value to the string s := ';⁾vṾWṁ$X€'.
            Ṿ  Uneval; construct a string representation of s.
               This yields r := '“;⁾vṾWṁ$X€”'.
           v   Dyadic eval; evaluate s with argument r.


 ;⁾vṾWṁ$X€     Evaluated link (s). Argument: r

  ⁾vṾ          Yield 'vṾ'.
 ;             Concatenate r with 'vṾ'.
               This yields t := '“;⁾vṾWṁ$X€”vṾ', i.e., the original source code.
       $       Combine the previous two links into a monadic chain.
     W           Wrap; yield ['“;⁾vṾWṁ$X€”vṾ'].
      ṁ          Mold; repeat ['“;⁾vṾWṁ$X€”vṾ'] once for each charcter in t.
        X€     Random each; select a character, uniformly at random, of each
               of the 13 repetitions of t.

Dennis

Posted 2016-09-07T21:44:43.027

Reputation: 196 637

6

Perl, 59 bytes

$_=q{$_.='$_=q{};eval';@a=/./g;s/./$a[rand@a]/g;print};eval

I used an existing quine as a basis and modified it to print random characters from the source contents.

Usage

Save as faux-source-code.pl and run using:

perl faux-source-code.pl

Produces something like the following:

$d='=a{f.gng$d._{{{ag{ed{aa;ae/r$no{a]_q}/$;_}lrq=r_=;_;=$'
vptr.q'ap.vaa@}@{iel];na;f.o/qon/fa}ie;=e{/a}/ag.$vaiqa_gv'
$_..'daq;.;/./.@._ogd;@aapqirv/;nrp=}@$}a/i;vq;.l.l@i}g]qq'
va==/t@dl.fe'}ar.l@n;_tve@=n$;$}$.l'p{a@qv._qag@dgr_$/.$/;v
q{/@d;@a;a_=g_r$r/.qar{=[gnr';@;$qgvad;$===/$//i]}g[tr@@.q}

In a brief test, ~3% of the results of the program eval successfully. I'm not sure what that says about Perl...

Dom Hastings

Posted 2016-09-07T21:44:43.027

Reputation: 16 415

Ahah, that comment about the 3% of successful eval! Nice one! ;-) – Dada – 2016-09-30T19:42:51.233

@Dada Seriously! The submissions in the answer genuinely work! I was pretty impressed... – Dom Hastings – 2016-09-30T19:45:02.843

Hopefully, from what I've seen, it just comes from the output being a entire single quoted string (with ' or q//, q{} etc) ! – Dada – 2016-09-30T19:52:22.340

@Dada Yeah, or a regex match. Made me chuckle though! :) – Dom Hastings – 2016-09-30T21:11:45.797

1Happy to see you golfing again btw! :) – Dada – 2016-09-30T21:20:10.063

4

Japt, 22 bytes

"+Q ²£ZgMqB"+Q ²£ZgMqB

Test it online!

How it works

"+Q ²£ZgMqB"+Q ²£ZgMqB  // Implicit: B = 11
"+Q ²£ZgMqB"            // Take this string.
            +Q          // Append a quotation mark.
               ²        // Double the result.
                £       // Replace each char in the result Z with
                 Zg     //  the char in Z at index
                   MqB  //   random integer in the range [0, 11).
                        // Implicit: output last expression

ETHproductions

Posted 2016-09-07T21:44:43.027

Reputation: 47 880

4

Pyth, 16 Bytes

smO+N"m1NOs+6"16

try it online!

Contains each char twice therefore the probability is the same as if each was only in there once.

smO+N"m1NOs+6"16     #
   +N"m1NOs+6"       # Add a quotation mark to the string: "m1NOs+6
  O                  # random choice from the string
 m            16     # do this 16 times.
s                    # join the list into a string

KarlKastor

Posted 2016-09-07T21:44:43.027

Reputation: 2 352

3

PHP, 71 140 110 124 140 120 bytes

for($i=2*$n=strlen($s='for($i=2*$n=strlen($s=.chr(39));$i--;)echo$s[rand(0,$n-1)];'.chr(39));$i--;)echo$s[rand(0,$n-1)];

run with php -d

  1. creates a string containing the code without the quotation marks
  2. and concatenates the quotation mark once using ord
    (same probability as if I would double the string and add two quotes);
  3. then loops over twice the length of the string to get random characters from it.

Can possibly be golfed further, but my attempts on eval where futile so far.
I will probably not go deeper here.

Titus

Posted 2016-09-07T21:44:43.027

Reputation: 13 814

1The probability of each character is its frequency in the original source code. I may be wrong, but it doesn't look like this entry meets this requirement. – ETHproductions – 2016-09-07T22:34:19.100

Oh I missed that point. Back to the editor. How can this be done without reading the code? – Titus – 2016-09-07T22:35:57.553

Using this, I got a syntax error, unexpected '<'. But I'm not familiar with PHP, how do I test this?

– NonlinearFruit – 2016-09-08T01:00:11.383

@NonlinearFruit: Did you use the -d flag? This is supposed to be saved to a file and then called with php or php-cgi without any flags. Maybe you can use a heredoc. – Titus – 2016-09-08T01:49:15.883

@NonlinearFruit: ... or just remove the leading <? for usage with -d. – Titus – 2016-09-08T12:56:21.507

+1 It works! (the -cgi did it) But I think it is outputing 142 characters instead of 140 – NonlinearFruit – 2016-09-08T13:10:04.733

@NonlinearFruit: You´re right. I will debug. – Titus – 2016-09-08T14:01:15.980

3

Python 2, 88 bytes

s='''from random import*; print "".join(choice(s) for c in "s='"+s+"';exec s")''';exec s

All actual merit in getting this far goes to mbomb007 - thanks for your help (and the pointer about backslashes)

user59421

Posted 2016-09-07T21:44:43.027

Reputation: 31

1This is a quine-like challenge, without input or reading your source code (suppose it is n characters long), you need to print n random characters. Where the probability of a symbol c being chosen is equal to (number of times c occurs in your solution) / n. – NonlinearFruit – 2016-09-08T16:05:16.550

So more like this?

exec("""s = 'from random import choice; print "".join([choice(s) for c in s])'; exec(s)""") – user59421 – 2016-09-08T16:23:45.893

You haven't included the single quotes yet, and you don't need the square brackets within the join. – mbomb007 – 2016-09-08T16:36:08.130

Thanks - and right, I got a little caught up in the rush of nudging closer to the solution – user59421 – 2016-09-08T16:37:06.543

And you can exec s if you restrict yourself to Python 2. Also you haven't included s =. – mbomb007 – 2016-09-08T16:37:26.593

1Here you go: s='''from random import*;print"".join(choice(s)for c in s+"s='';''exec s''")''';exec s. I wish I'd thought of that. – mbomb007 – 2016-09-08T16:41:33.090

+1 It works! But I'm getting a 84 character output.. – NonlinearFruit – 2016-09-08T18:22:56.700

@user59421 Your program is currently incorrect. Look at the differences between what you have and this: s='''from random import*;print"".join(choice(s)for c in s+"s='';''exec s''")''';exec s – mbomb007 – 2016-09-09T18:11:53.950

3

Ruby, 47 bytes

eval r="47.times{$><<('eval r=%p'%r)[rand 47]}"

This is based on the standard eval quine:

eval r="$><<'eval r=%p'%r"

It's a byte longer than the shortest quine, but it's usually the better choice for generalised quines, because any computation done on the source code string does not need to be duplicated. Whereas in the usual quine, every additional computation needs to go both inside and outside the main string, it is only needed inside the main string for this kind of quine.

As for what the code actually does: after obtaining a string representing the entire source code, we simply select a random character (by selecting a random index) 47 times and print each character separately.

Martin Ender

Posted 2016-09-07T21:44:43.027

Reputation: 184 808

3

Wolfram Language/Mathematica, 109 Bytes

Function[Print[StringJoin[RandomChoice[StringSplit[StringJoin[ToString[FullForm[Slot[0]]],"[]"],""],109]]]][]

sample output:

niPi[no,ili[Siu[,Sdoio9nthg"t ginuu[1[o]"i,icgi[0TncrS"[ln"o0]r,i][Jon[[et]0"]m [ri"a[]motrin,iFoFnultnnno,Jl

Oh those square brackets.

chuy

Posted 2016-09-07T21:44:43.027

Reputation: 389

2

Jelly, 44 bytes

I hope I have interpreted all the rules correctly (I'm not quite sure what the "carry payload" thing is in meta or if it's even relevant to this challenge).

“ẋ2;8220Ọ;8221ỌXµ44СḊ”ẋ2;8220Ọ;8221ỌXµ44СḊ

Test it out at TryItOnline

This constructs a string from which to choose characters. The initial string has all the character used except the open and close quotes. It then doubles that string and concatenates one of each of the open and close quotes from ordinals (hence the need to double the other characters). Lastly it repeatedly picks random characters from the composed string to the length of the program.

Jonathan Allan

Posted 2016-09-07T21:44:43.027

Reputation: 67 804

1@NonlinearFruit Oops - I updated to add a missed character from my string but did not update to 44 - thanks! – Jonathan Allan – 2016-09-07T23:03:00.227

2

Pyke, 35 bytes

35F\";"\\+3322 5**F;H)s"\"2*+2* H)s

Try it here!

To check: remove the final H and the resulting string contains the right number of each character (with the extra H)

This does NOT use a generalised quine or in fact a quine at all. It relies on being able to create a string containing all the characters in the source. It should be able to do it for any code but each character logarithmically increases code size. The only number of times a character is allowed in the source is 2 or 7

Blue

Posted 2016-09-07T21:44:43.027

Reputation: 26 661

2

C, 125 bytes

char*s="char*s;l,i;f(){l=i=strlen(s);while(i--)putchar(s[rand()%l]);}";l,i;f(){l=i=strlen(s);while(i--)putchar(s[rand()%l]);}

C, 60 bytes for golfed but not quine code taking any string

l,i;f(char*s){l=i=strlen(s);while(i--)putchar(s[rand()%l]);}

While for counting characters my solution needed 86:

c[256];i;f(char*s){i=256;while(*s)c[*s++]++;while(--i)while(c[i]?c[i]--:0)putchar(i);}

VolAnd

Posted 2016-09-07T21:44:43.027

Reputation: 296

It should not? Perhaps I do not understand the rules of this quiz. My f takes string and prints to standard output: string can be any sequence of characters. – VolAnd – 2016-09-08T12:01:33.777

@NonlinearFruit Probabilities not calculated but expression rand()%LENGTH_OF_STRING take character according to probability of that character with normal distribution provided by rand(). Perhaps, I do not understand quine approach for C.... – VolAnd – 2016-09-12T09:03:43.507

+1 The new solution is nearly correct. s just needs to contain char*s="";. I think something like this char*s="char*s=l,i;f(){l=i=strlen(s);while(i--)putchar(s[rand()%l]);};+''"+'""' would do it (but I am not familiar with C). – NonlinearFruit – 2016-09-12T16:08:18.747

If the answer is not valid in its current state, then it should be deleted. – mbomb007 – 2016-09-28T13:29:07.207

@mbomb007 Could you explain your judgment and possibly provide come advice? – VolAnd – 2016-09-29T05:47:12.447

@NonlinearFruit Maybe you can explain. – mbomb007 – 2016-09-29T13:54:52.987

@VolAnd Your string should contain a copy of your code. char*s=""; is part of your code but it does not show up in your string. That is to say, you had a working solution that you made into a quine, but you are not 'quining' the parts that you added to make that happen. – NonlinearFruit – 2016-09-30T03:41:35.253

I have added char*s; in the string. Thanks for comments. – VolAnd – 2016-09-30T05:11:20.160

2

Ruby, 81 67 bytes

Saved a bunch of bytes by stealing some tricks from Martin's solution

s="s=%p;67.times{$><<(s%%s)[rand 67]}";67.times{$><<(s%s)[rand 67]}

I didn't realize that you had to randomly select every time; I thought a shuffle would do the trick. This can probably be golfed, but it's the shortest I could get it.

Standard Ruby quine with a few modifications so it prints out the shuffled string. I'm sad because it took like fifteen minutes to figure out the formatting quirks before I realized that I was subconsciously stealing it anyway.

I think the string shuffling can be shortened but I don't know how; I might also be able to finagle the formatting into being shorter once I put some thought into it. Help would be appreciated.

Try it online!

Fund Monica's Lawsuit

Posted 2016-09-07T21:44:43.027

Reputation: 564

I think (like my CJam) answer, it's not necessary to use a standard quine as the basis. A direct port of my CJam solution gives 64 bytes: 64.times{$><<"64.times{$><<.inspect[rand 32]}".inspect[rand 32]} – Martin Ender – 2016-09-09T08:44:08.843

Nevermind, basing it on a standard quine is shorter, but you'll have to use the eval-based quine: eval r="47.times{$><<('eval r=%p'%r)[rand 47]}" – Martin Ender – 2016-09-09T08:53:35.247

@MartinEnder That's different enough to merit its own answer, I think. If you disagree, feel free to edit it into mine, but in the mean time I'll just steal a few tricks from yours to save a few bytes in mine. – Fund Monica's Lawsuit – 2016-09-09T14:05:33.233

2

JavaScript, 128 bytes

a=";a+=uneval(a);alert(a.replace(/./g,_=>a[Math.random()*64|0]))a=";a+=uneval(a);alert(a.replace(/./g,_=>a[Math.random()*64|0]))

Note: only works in Firefox due to the use of uneval.

Sample runs:

)a(rgc=d6m_a4uar=hp(lll(,d=m=dee(M(gtraoan0)(M(aaaa(M]c)e)/M()/u//M6_n/a"*unea(/>atugrn(a=nav"|;)|=)/,ataa,aaangtue;am)t0;|ctoa/
=lvct;eee,,a.e=6r0;);Mtaaoa.aeea4)a[r.6]e/ll+l.)=)|a[(c"rao4ea/=_acaMh=veerva"a(_(d(l)lgn.;rM">=ea40a*).e(h(laa6r)4a)rhlar=t(ta[
[rt]ll]n))aota.e)g;>ae*;..4tt];l[;].*lnr4(mnM|alg(a.ag(.=e(a>>aa>.hga;a/pat+elc];apc=(ag)tao.).ll4u)dah]r(ul)>lr;,)ret(e/g(=_c*r
M.r)_;.a(lraalg("mac>dmrlr"0/ah(a()ead|/0a(m.|u0)(a(0_[dn)a]/raal;eata)a.ataeaa*l)=ra()la=(a)*aaea>n;.a.)ca)orM(tm*a,a=)p;(>r)aa

ETHproductions

Posted 2016-09-07T21:44:43.027

Reputation: 47 880

I'm now really surprised that this produced more valid code in Perl than it appears it would in JS! Not as many fun words here, except gtraoan which is nearly a groan I guess... – Dom Hastings – 2016-11-02T21:04:58.037

1@DomHastings Well, Perl is more of a mash of punctuation than JS ;) – ETHproductions – 2016-11-02T21:06:14.693

Definitely! It's more of a mess of punctuation than an explosion in a punctuation factory! but I quite like that! – Dom Hastings – 2016-11-02T21:09:18.090

Does " have a probability of showing up? – NonlinearFruit – 2016-11-02T21:11:13.250

1@NonlinearFruit Yup. There's at least one in the first, second, and last example outputs. – ETHproductions – 2016-11-02T21:12:13.870

1

Python 3, 134 132 bytes

I use every character in my source code within the string the correct number of times, then multiply the string by two to include itself. The program prints a random character from that string for each character in the code (the length is hard-coded.)

from random import*
for i in[0]*134:print(choice("""from random import*
for i in[0]*134:print(choice(""*""2""),end='')"""*2),end='')

Try it online

I avoided backslashes like the plague. As soon as the code contains \n or \", you have a problem, because the string doesn't contain backslashes yet, so you have to add those also, but in a separate string multiplied by a higher number, because it takes two backslashes to represent one (\\).

Example output:

i(tc*"3]i o''r=,,,h34t"r
ri"](fco t)niap)t "it2nc0o  npoi3'"nto(*4 i(ido' r*4f"oi]d rm ,i"eif)m"d
m emi
dfr n*p 3*(i""r1d"dr menc hio'

I gotta say, it reminds me of FlogScript.

mbomb007

Posted 2016-09-07T21:44:43.027

Reputation: 21 944

1

PowerShell v2+, 175 bytes

$d='$d={0}{1}{0}{2}-join(0..174|%{3}[char[]]($d-f [char]39,$d,"`n",[char]123,[char]125)|Random{4})'
-join(0..174|%{[char[]]($d-f [char]39,$d,"`n",[char]123,[char]125)|Random})

Quines in PowerShell suck, because the string replacement delimiters {} also denote loops and whatnot, so you need to use a bunch of chars in the -f operator, which bloats the code.

Similar-ish to my Quine on Every Line answer. Basically we loop from 0 to 174 and each iteration re-calculate the quine $d, cast it as a char-array, and pull out a Random element chosen uniformly from the input. By definition, this gives probability (occurrences in source) / (length of source) as required. Those characters are encapsulated in parens and -joined together back into a string.

Example

PS C:\Tools\Scripts\golfing> .\faux-souce-code.ps1
}}[${hr[`ini}}] [5i,=[]0,j2($=n4(dm]jh]jc]]7
}..j"rnj9|fn,4r]{9]('["jdh0}$rd,-f,a.c"}{h1 ]5d,),0n5|nh(]73a9da4aRi[5}a}430}}rd$,$r)-hhr%or79-R.R-`'r'aa|=1f0][|[{7}do1]$ja0 rd{h

(Yes, that's a newline in the output -- when a string containing a newline is char-array'd, the `n is treated as a character, since a char-array is just an array of byte codes, so it also has a 1/175th chance of being selected.)

AdmBorkBork

Posted 2016-09-07T21:44:43.027

Reputation: 41 581

1

Dyalog APL, 20 bytes

f←{(,⎕CR'f')[?⍴⍨20]}

f←{...} define f as

(,⎕CR'f') listified (,) Character (table) Representation (⎕CR) of f ('f')

[?⍴⍨20] indexed with ([...]) random-up-to (?) repeat-itself-times (⍴⍨) of twenty

Let us run it (with a dummy argument) a few times:

      f⍬
)0'0](⍨(([],}⎕))⎕'f2
      f⍬
{'['}f[←R[)2←?}⍨]}C2
      f⍬
,,⍨←?2}⍴?'⍨}C,'{⎕(C0

Fine, but is the distribution correct? Let us run it on 10,000 dummy arguments and see how many times each character occurs:

      {⍺ , 1E¯4× ⍴⍵}⌸ ∊ f¨ ⍳1E4
C 0.9952
⎕ 0.9996
' 1.9777
f 2.004 
← 1.0018
⍨ 1.0173
0 1.0213
] 1.0049
[ 0.9988
2 0.9943
{ 0.9895
) 1.0093
R 1.0054
, 1.0029
? 0.9943
} 0.9861
⍴ 1.0032
( 0.9944

Clearly, f and ' occur twice as often as the other characters, just like in the original source code.

How did we do it?

{⍺ , 1E¯4× ⍴⍵}⌸ ∊ f¨ ⍳1E4`

⍳1E4 generates the first 10,000 integers

runs f on each of those numbers

flattens all the pseudo-quines into a single 200,000-character string

is a higher-order function which for each unique character in the right side data, feeds the left-side function the unique element as left-argument and the indices where that character occurs as right-argument. The left-side function is

{⍺ , 1E¯4× ⍴⍵}

left-argument, i.e. the unique character

, followed by

1E¯4× 1×10⁻⁴ times

⍴⍵ the shape of the right-argument (the occurrence indices), i.e.how many times it occurs

Finally, puts it all together in a table.

Adám

Posted 2016-09-07T21:44:43.027

Reputation: 37 779

1

C#, 277 280 268 bytes.

using System;class a{static void Main(){var s="using System;class a{static void Main(){var s=\"x5Cx5C\x5C\x5C\";Random d=new Random();for(int i=0;i++<268;)Console.Write(s[d.Next(0,134)]);}}";Random d=new Random();for(int i=0;i++<268;)Console.Write(s[d.Next(0,134)]);}}

Ungolfed:

using System;
class a
{
    static void Main()
    {
        var s="using System;class a{static void Main(){var s=\"x5Cx5C\x5C\x5C\";Random d=new Random();for(int i=0;i++<268;)Console.Write(s[d.Next(0,134)]);}}";
        Random d=new Random();
        for(int i=0;i++<268;)
            Console.Write(s[d.Next(0,134)]);
    }
}

Pretty sure this works correctly.

Sample output:

    fn;i)(]ns;<ftt08et]i+ii8]m[W}dr{rmte,)t edayid 2s cmsee\;ta["e n;o}]iolys;t sftoR{.=g vs8;(sd isWrecn++iia]iuf"avs\i<{ee vfs[ensin\s i]0a(We.0ns R(2roo=ldxil\{t(o"aistt.;.  r w"m1];idi}Ctitiindnn;M[,[+0(,o"]mca[rmnm)<;n"8ReaystinRsanr([(d,n\.ateiR sd.=[=;ttn.;wna)cCt[=+t{Wxs(\}rg

Yodle

Posted 2016-09-07T21:44:43.027

Reputation: 2 378

@NonlinearFruit Thanks, missed that space. Also means I can't use a foreach loop which adds a few bytes :(. However, I think I do have " included correctly with those two escaped quotes in the string, since they appear in the output a few times, unless I'm missing their use somewhere else. – Yodle – 2016-09-09T14:05:38.667

Ahh, I thought they didn't count if they were in the string, my bad. Will fix in a bit. – Yodle – 2016-09-09T14:17:16.087

Okay, 's now appear as well! – Yodle – 2016-09-09T14:26:46.227

1Hm, interesting problem then. Can't just keep adding \ or I'll always be one short. I'll use the ascii code for \ instead. – Yodle – 2016-09-09T14:46:45.610

Does (new Random()).Next(0,134)] work? It would save a couple bytes. – NonlinearFruit – 2016-09-12T16:10:21.877

It appears as though a new random class each iteration uses the same seed multiple times resulting in non-random output (the same character the entire time). – Yodle – 2016-09-12T16:43:12.723

1

C, 136 bytes

main(a){for(a=136;a--;)rand()%68?putchar("main(a){for(a=136;a--;)rand()%68?putchar([rand()%67]):putchar(34);}"[rand()%67]):putchar(34);}

Example output:

;%7c(u)"r4-hd)nnr-%n6;6(4or(n4(6(a:=a3r-:()hp(:aa%;4rru}h;(a()3mh3rdi7));a-u36:r3on[4?p((]6n6?()-6t736unhr%:[%[[d(p:[ru)-n(6r=:](p-})8"]

This program outputs 136 characters randomly.

The entire source code (less " quotation marks) is contained in a string. The program determines the probability of outputting a quotation mark as 2/136, otherwise outputting one of the other 67 characters randomly.

There are two occurrences of each character in the string in the program. The probability of outputting a character from the string is 134/136. The probability of choosing a specific character in the string is 1/67. So the chance of outputting a character in the string is 134/136 * 1/67 = 2/136. There are two occurrences of each string character in the program, so there is a 1/136 probability of outputting a character for each occurrence in the program.

The order of symbols inside the string doesn't matter.

user61383

Posted 2016-09-07T21:44:43.027

Reputation: