# Shortest code to produce non-deterministic output

You need to produce output that is non-deterministic.

In this case, this will be defined to mean that the output will not always be the same result.

Rules:

• A pseudo-random number generator that always has the same seed does not count.

• You can rely on the program being run at a different (unknown) time each execution.

• Your code's process id (if it's not fixed by the interpreter) can be assumed to be non-deterministic.

• You may rely on web-based randomness.

• Your code may not take non-empty input. Related meta post.

• The program is not required to halt, but the output must be displayed.

• @mbomb007 In C there are many things that are simply "undefined" behaviour. Any given interpreter is allowed to do whatever it wants in any situation. For all we know, gcc might order you a pizza if you try to overflow a signed integer on a rainy Tuesday, but will make a trout jump out of your screen on all other days. So you wouldn't really ever know if it's actually deterministic or not in any given implementation. – Martin Ender Nov 30 '16 at 20:44
• @MartinEnder I'm not sure if that matters. We define languages here by their implementation, not by the specification (as languages without an implementation is not allowed) – Nathan Merrill Nov 30 '16 at 21:00
• @MartinEnder Yeah, I agree with Nathan. – mbomb007 Nov 30 '16 at 21:01
• Note that undefined behaviour in C often leads to crashes, and crashes on UNIX and Linux lead to core files which contain the process ID inside them. That would seem to comply with the question as currently worded. – user62131 Nov 30 '16 at 21:23
• Unless I misunderstood, the question did not ask for code that takes advantage of undefined behavior. It asks for code that takes advantage of defined behavior to guarantee non-determinism. – WGroleau Dec 1 '16 at 3:30

# Groovy, 9 bytes

{print{}}

Outputs:

Try it online!

$? is the random number predicate. When given an integer as input (here, 9), its output will be unified with an integer between 0 and 9 uniformely at random. # Randwork, 11 bytes Uses the Randwork+ instruction set, because that's the only specification with an existing interpreter. Do anything This statement executes a random instruction from the instruction set. There is a 7/28 (25%) chance of non-empty output. I calculated the probability by viewing the source code of the interpreter. The instructions that can produce output are: Write the ASCII equivalence of a random byte Beep Write the ASCII equivalence of byte 1 Write the ASCII equivalence of byte 2 Write the ASCII equivalence of byte 3 Write the ASCII equivalence of byte 4 Display the Hello World message Bytes 1-4 have not been set, so output of any of them will be a NUL byte. The 7 possibilities of non-empty output are (in corresponding order): \x?? - a random byte \x07 - the bell character (beep) \x00 - NUL \x00 \x00 \x00 Hello world ## PHP 10 bytes <?=rand(); Prints a random number between 0 and getrandmax(). Which may vary based on what computer it's run on. # Java2K, 9 bytes I don't recommend trying to write an approximation of a deterministic program in this language. 11 6/*/_\ This function has a 90% chance to return 1, otherwise it will return a random number. 11 6 is the name of the division function. A function is called like <name>/<arg0>/<arg1>\. Basicaly every function returns the "correct" result 90% of the time, or else a random number. The token * is replaced by a random number, say 203. The _ token is replaced by the previous argument, i.e. 203. So, this function will divide 203 by 203 which has (see below) a 90% chance of returning 1. # TI-83 Hex Assembly, 4 bytes PROGRAM:ND :AsmPrgm :EF0A45 :C9 Run it with Asm(PrgmND). Calls the _PutS system library call (0x450a), but because it doesn't set HL it will print whatever HL pointed to last, usually a lot of garbage text. I count this as 4 bytes, because each pair of hex digits is one byte. # Ruby, 14 bytes p ?..object_id Returns object id of the string '.' # TI-Basic, 2 bytes Very similar to this answer. The getTime token is two bytes and is located at EF 0A. getTime • rand is 1 byte. – bb94 Mar 19 '19 at 0:18 • @bb94 "A pseudo-random number generator that always has the same seed does not count." – Timtech Apr 2 '19 at 0:34 # C#, 72 bytes It's alot longer than the other C# answer but hey, different approach and fully functioning console application. Why not? ## Golfed using System;class P{static void Main(){Console.Write(Guid.NewGuid());}} ## Ungolfed using System; class P { static void Main() { Console.Write(Guid.NewGuid()); //Create a new random GUID and print it } } # BrainFlump, 5 bytes :+:;. Try it online! Outputs either a NUL or SOH character ## Explanation BrainFlump is the latest iteration of BrainFl* languages having different memory models (BrainFlak is a stack, BrainFlueue is a queue, etc) In BrainFlump, memory consists of a Cell and a Dump. The Cell is a single numerical value, and the Dump is an unordered collection of numerical values. When the program starts, the Dump is empty, and the Cell is 0. : Push the Cell's value to the Dump + Increment the Cell : Push the Cell's value to the Dump ; Pop a value from the Dump (randomly) to the Cell . Print the Cell's value as an ASCII character The Cell's value will either be 0 or 1, and as it's printed as an ASCII character, this results in NUL or SOH # Kotlin script (.kts), 12 bytes print(Any()) Any is a compile-time time wrapper for Object, default toString() of any object is class name@hashcode. Probably the shortest solution that runs on the JVM. If .kts is cheating: 18 bytes: fun a()="${Any()}" (forgot functions are a valid answer)

38 bytes: fun main(a:Array<String>)=print(Any())

• Trying this on my OpenJDK JRE with a freshly downloaded kotlinc 1.0.5-2 repeatably outputs java.lang.Object@5bc1903. Doesn't seem too nondeterministic? – Paŭlo Ebermann Dec 4 '16 at 19:31
• Hm, didn't think of that - is it still a valid answer if it's different on every machine? Default hashcode impl. uses the internal memory address of the object IIRC. – F. George Dec 5 '16 at 4:23
• Just out of curiosity, what does it output on your machine? – Paŭlo Ebermann Dec 5 '16 at 18:02
• java.lang.Object@21471ca8 but it seems to vary between IDE restarts and even how I name the source file. Makes sense, as the hashcode is literally just the memory address of the object. – F. George Dec 5 '16 at 20:29