Shortest code to produce non-deterministic output

83

3

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.

Leaderboard

function answersUrl(a){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+a+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(a,b){return"https://api.stackexchange.com/2.2/answers/"+b.join(";")+"/comments?page="+a+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(a){answers.push.apply(answers,a.items),answers_hash=[],answer_ids=[],a.items.forEach(function(a){a.comments=[];var b=+a.share_link.match(/\d+/);answer_ids.push(b),answers_hash[b]=a}),a.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(a){a.items.forEach(function(a){a.owner.user_id===OVERRIDE_USER&&answers_hash[a.post_id].comments.push(a)}),a.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(a){return a.owner.display_name}function process(){var a=[];answers.forEach(function(b){var c=b.body;b.comments.forEach(function(a){OVERRIDE_REG.test(a.body)&&(c="<h1>"+a.body.replace(OVERRIDE_REG,"")+"</h1>")});var d=c.match(SCORE_REG);d?a.push({user:getAuthorName(b),size:+d[2],language:d[1],link:b.share_link}):console.log(c)}),a.sort(function(a,b){var c=a.size,d=b.size;return c-d});var b={},c=1,d=null,e=1;a.forEach(function(a){a.size!=d&&(e=c),d=a.size,++c;var f=jQuery("#answer-template").html();f=f.replace("{{PLACE}}",e+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link),f=jQuery(f),jQuery("#answers").append(f);var g=a.language;g=jQuery("<a>"+g+"</a>").text(),b[g]=b[g]||{lang:a.language,lang_raw:g,user:a.user,size:a.size,link:a.link}});var f=[];for(var g in b)b.hasOwnProperty(g)&&f.push(b[g]);f.sort(function(a,b){return a.lang_raw.toLowerCase()>b.lang_raw.toLowerCase()?1:a.lang_raw.toLowerCase()<b.lang_raw.toLowerCase()?-1:0});for(var h=0;h<f.length;++h){var i=jQuery("#language-template").html(),g=f[h];i=i.replace("{{LANGUAGE}}",g.lang).replace("{{NAME}}",g.user).replace("{{SIZE}}",g.size).replace("{{LINK}}",g.link),i=jQuery(i),jQuery("#languages").append(i)}}var QUESTION_ID=101638,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",OVERRIDE_USER=34718,answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;float:left}table thead{font-weight:800}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table></div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table></div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table><table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table>

mbomb007

Posted 2016-11-30T20:19:41.190

Reputation: 21 944

What about undefined behaviour? – Martin Ender – 2016-11-30T20:32:42.280

@MartinEnder Undefined based on the implementation, or based on where it's run? – mbomb007 – 2016-11-30T20:38:01.897

33@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 – 2016-11-30T20:44:34.687

12@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 – 2016-11-30T21:00:51.950

2@MartinEnder Yeah, I agree with Nathan. – mbomb007 – 2016-11-30T21:01:23.167

@NathanMerrill My point was that for undefined behaviour we can't really tell to what degree it's non-deterministic unless we reverse engineer the implementation. Undefined behaviour is basically the definition of non-deterministic, but any given implementation may for any given set of circumstances decide to always to the same thing when you run the code. – Martin Ender – 2016-11-30T21:04:38.977

1That's true. Non-deterministic is defined in the specification, not the implementation (because you can't detect determinism in a black box). – Nathan Merrill – 2016-11-30T21:06:08.693

1@MartinEnder Any non-determinism defined (or not defined?) in the spec is not referring to a single implementation, but to all of them. It's simply trying to say don't rely on it. But for an answer, I'd say you would need to look at the implementation and prove that the answer is not always the same, especially if I were to run it and it's always the same for my implementation I'm running that's the same as yours. – mbomb007 – 2016-11-30T21:08:14.250

@mbomb007 Undefined behaviour is not the same as implementation defined behaviour. Undefined behaviour does allow to do anything under any circumstances (and is often the cause of irreproducible bugs). And always returning the same thing is not a reliable measure of randomness.

– Martin Ender – 2016-11-30T21:12:26.677

@MartinEnder If I can run it and see different results for the same implementation, I'll allow it. – mbomb007 – 2016-11-30T21:15:31.520

7Note 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. – None – 2016-11-30T21:23:14.857

1@ais523 Stderr is not valid by consensus. Consensus requires something like 3/4 upvotes out of total votes. Also, you can't say "often". It has to be in the code, guaranteed to output the required non-deterministic result. – mbomb007 – 2016-11-30T21:28:43.257

Consensus says that output to a file is valid. The crash dump is a file, with the filename core. – None – 2016-11-30T21:29:47.297

@ais523 If I can't validate the answer, it's not valid. – mbomb007 – 2016-11-30T21:30:35.590

1So if the seed of the random generator is set to a different (random) value each time by default, can a random number generator be used? – Luis Mendo – 2016-11-30T21:48:58.427

@LuisMendo Yes, if the randomness that determines the seed is not deterministic. – mbomb007 – 2016-11-30T22:06:49.160

5Unless 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 – 2016-12-01T03:30:58.510

1What do you mean by "Your code may not take non-empty input."? Surely a program that doesn't input anything anywhere can't be nondeterministic. – Angs – 2016-12-01T17:33:36.033

@Angs http://meta.codegolf.stackexchange.com/a/7172/34718

– mbomb007 – 2016-12-01T17:41:19.800

2@MartinEnder damn, missed my free GCC pizza yesterday. – Mindwin – 2016-12-02T12:04:36.233

Now that there are a bunch of function answers, I'd just like to clarify: Are function entries allowed? – ETHproductions – 2016-12-02T22:28:52.923

@ETHproductions My earlier comment appears to have been deleted. Yes, I was intentionally vague in order to allow the default (full program or function). – mbomb007 – 2016-12-03T04:51:07.000

For C with undefined behaviour, main=0; would produce a non-deterministic core-file in 7-bytes. – Mark K Cowan – 2016-12-06T15:34:59.510

You say that the program does bot need to halt. Would a program that either halts or loops forever with a 50% chance of each be non-deterministic? – Post Rock Garf Hunter – 2018-08-23T03:22:49.447

@WW I don't think that would count as "output". The not needing to halt means that output should happen in either case. The output could be empty string for one of them. – mbomb007 – 2018-08-23T18:03:28.080

Can we use environment variables as a source of non-determinism? – Esolanging Fruit – 2019-02-18T07:24:27.140

@EsolangingFruit No, because those are generally either defaults or set by the user. They don't really change, and consecutive runs of your program would always output the same result. – mbomb007 – 2019-02-18T15:00:05.953

Answers

36

huh?, 0 bytes


An empty program still produces output. The last lines of the Python interpreter that are executed:

print "..."
f = open('Notes.txt', 'w')
f.write(time.strftime("%c") + " - The user tried to give me commands again. I still have no idea what they are talking about...\n")

At the end of a program, the Python interpreter will print ..., then it will create/open a text file called Notes.txt and write a string which contains the current time in front.

mbomb007

Posted 2016-11-30T20:19:41.190

Reputation: 21 944

5Of all the things I thought people would use on my GitHub, I didn't think a joke language interpreter would be one :P – Kade – 2016-12-02T18:41:39.323

@Kade I was actually going to use it to answer another question as well (shortest code to play a sound, with only a single byte) -- but the question is now closed. – mbomb007 – 2016-12-02T19:36:59.787

Though it'd be non-competing unless I looked at the original .NET interpreter, I guess. – mbomb007 – 2016-12-02T19:43:09.337

110

WinDbg, 1 byte

#

Wow! Never expected a 1 byte solution from WinDbg!

# searches for a disassembly pattern, but since there's no parameters, it looks to just return the next assembly instruction in whatever dump/process you're attached to. Not sure the logic for setting the initial address, but it does.

Sample output:

0:000> #
Search address set to 75959556 
user32!NtUserGetMessage+0xc
75959556 c21000          ret     10h

0:000> #
user32!NtUserGetMessage+0xf 
75959559 90              nop

0:000> #
user32!NtUserMessageCall 
7595955a 90              nop

0:000> #
user32!NtUserMessageCall+0x1 
7595955b 90              nop

0:000> #
user32!NtUserMessageCall+0x2 
7595955c 90              nop

0:000> #
user32!NtUserMessageCall+0x3 
7595955d 90              nop

0:000> #
user32!GetMessageW
7595955e 8bff            mov     edi,edi

0:000> #
user32!GetMessageW+0x2 
75959560 55              push    ebp

0:000> #
user32!GetMessageW+0x3 
75959561 8bec            mov     ebp,esp

0:000> #
user32!GetMessageW+0x5 
75959563 8b5510          mov     edx,dword ptr [ebp+10h]

milk

Posted 2016-11-30T20:19:41.190

Reputation: 3 043

9One of the cooler answers here, this should win over a "Current Date" solution in my opinion. – Magic Octopus Urn – 2016-11-30T21:39:33.343

that above it seems the disassebly, step by step of the begin of some function in 386 intel cpu assembly – RosLuP – 2016-12-02T22:05:33.550

60

Java 7, 33 30 27 bytes

int a(){return hashCode();}

Because Java.

Poke

Posted 2016-11-30T20:19:41.190

Reputation: 3 075

49Because Java. Probably the best explanation of Java ever. – F. George – 2016-11-30T21:35:54.753

1toString() also works, right? Outputs a random memory address if not overridden. – Magic Octopus Urn – 2016-11-30T21:44:21.557

5@carusocomputing I had toString in a previous version but then the return type is String which is longer than int. Save the bytes! :] – Poke – 2016-11-30T22:17:06.267

@Poke HA! I wondered what I over-looked there. Good catch. – Magic Octopus Urn – 2016-11-30T22:32:15.197

12Is this valid as a function? hashCode() is an abbreviation here for this.hashCode(), so it'd only work as an instance method, not a static method. In that case, you'd need additional code to create an object in the caller. That's relevant here because it's the code to create an object that's responsible for the nondeterminism. – None – 2016-12-01T01:08:04.367

@ais523 If I wanted it to be a static method I likely would have defined it as such. From what I've seen in the past a function is an acceptable answer for languages like java unless otherwise specified in the question. It is assumed to be part of a class and will run with the given definition in any class it's a part of. – Poke – 2016-12-01T01:31:28.113

It won't be nondeterministic if the class overrides hashCode; many do. I guess we have to assume that the method belongs to a class that extends Object directly and has no other code, and that we create an object of that class to run the code on… – None – 2016-12-01T02:38:16.950

1

@ais523 I think this meta post and comment should be relevant.

– Poke – 2016-12-01T04:59:56.690

15In Java 8: ()->hashCode() for 14 bytes. Just sayin' ;) – Olivier Grégoire – 2016-12-01T16:58:12.523

@OlivierGrégoire Yeah yeah but I'm still stuck in my ways :P – Poke – 2016-12-01T18:07:24.357

This snippet doesn't compile as Java code (t.java:1: class, interface, or enum expected). So it can't possibly produce an output. So it can't possibly produce nondeterministic output. – pts – 2016-12-02T17:47:52.570

4

@pts I'm going based off of the meta post discussing the default submit structure for posts. Functions are allowed by default unless the challenge specifies that a full program is required.

– Poke – 2016-12-02T18:36:16.240

1I tried to put this into a class and added a main method which calls this method: package codegolf.nondet101638;public class Test{int a(){return hashCode();}public static void main(String[]x){System.out.println(new Test().a());}}. Running it always outputs (on my OpenJDK 1.8) 1808253012. Doesn't seem too nondeterministic? – Paŭlo Ebermann – 2016-12-04T19:23:45.310

@PaŭloEbermann From the docs. "Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application." Also for future reference please note that my answer is for Java 7 and you tested with Java 8. It shouldn't matter this time

– Poke – 2016-12-05T00:38:48.840

@Poke just for curiosity, could you compile this program on your Java 7 implementation and run it several times? Does it output different results? – Paŭlo Ebermann – 2016-12-05T18:00:48.873

1

@PaŭloEbermann Eclipse with Java 7

– Poke – 2016-12-05T18:24:17.790

Thanks. So it looks like this determinism was added with Java 8, or with the Linux version. – Paŭlo Ebermann – 2016-12-05T18:27:48.427

52

MATLAB, 3 bytes

why

why provides answers to almost any question. A few examples:

why
The programmer suggested it.

why
To fool the tall good and smart system manager. 

why
You insisted on it.

why
How should I know?

This is shorter than any rand function I can think of.

Stewie Griffin

Posted 2016-11-30T20:19:41.190

Reputation: 43 471

33MATLAB has a builtin for this? Why? – ETHproductions – 2016-12-03T20:46:18.817

60@ETHproductions The programmer suggested it – Eddie Curtis – 2016-12-05T16:04:06.323

41

R, 1 byte

t

Outputs the function's source code and a memory pointer address which changes with every (re-)start of R.

chrki

Posted 2016-11-30T20:19:41.190

Reputation: 533

30

Befunge (-93 and -98), 3 bytes

?.@

The ? sends execution in a random direction. If it goes up or down, it loops back to the ? and rerolls. If it goes left, the program wraps round to the @ and thus exits without printing anything. If it goes right, it prints 0 (the output produced by . when the stack is empty) and then exits on the @.

user62131

Posted 2016-11-30T20:19:41.190

Reputation:

This isn't guaranteed to terminate, but I was going to post this exactly so +1 – Daniel – 2016-12-01T03:59:55.760

You may want to change the comma to a period to output 0 as a number instead of a null character (ASCII value 0). +1 – MildlyMilquetoast – 2016-12-01T04:19:38.890

It was . in the program I was using for testing, but somehow became a , when I copied it onto PPCG. Fixed. – None – 2016-12-01T05:04:20.967

7@Dopapp it terminates almost surely though, with probability 1. I'd take that as a guarantee ;) – Oliphaunt - reinstate Monica – 2016-12-01T09:17:19.277

@JamesHolderness I think you can do it in 1. Not sure if this counts though...

– MildlyMilquetoast – 2016-12-06T18:18:25.810

30

Labyrinth, 5 bytes

v
!
@

Either prints 0 or nothing (50% chance each).

Try it online!

There is a very specific case in which Labyrinth exhibits random behaviour:

  • There must be a wall in front of the instruction pointer and behind it.
  • There must be a non-wall left and right of the instruction pointer.
  • The current top of the stack must be zero.

If all of those conditions are met, the direction the IP moves in is chosen (uniformly) randomly. The cherry on top is that those three conditions are impossible to meet in regular control flow, which means unless you modify the source code at runtime.

(This may seem a bit arbitrary, but it's actually the most consistent behaviour I could find for these conditions, since normally the direction of the IP always depends on the previous direction, its neighbours, and the sign of the top of the stack, and this seemed like an elegant way to include a source of randomness in the language.)

With the help of the source code rotation instructions (<^>v) it's possible to bring the IP into this situation. One such example is seen at the top. The IP initially points east and starts at the top. The v rotates the current column so that we get:

@
v
!

The IP moves along with this rotation so that it's still on the v, pointing east. All the conditions are fulfilled now, so the IP will either go up or down randomly. If it goes up, the program terminates immediately. If it goes down, it prints a zero, rotates the column again, and then terminates.

There are three other programs making use of this (one which also prints 0, one which prints 00 and one which prints 000):

v
@
!

"
>@!

"
>!@

(Actually there are a lot more than three other programs, because you could also use . instead of ! to print null bytes, or replace that " with a large variety of commands, but I believe they all work essentially the same.)

Martin Ender

Posted 2016-11-30T20:19:41.190

Reputation: 184 808

29

Minecraft, 5 4 bytes

op 8

Used by typing into a server's console or a command block and giving it power. Can be run from the chat interface by prepending a /.

Usually this does nothing, but if there's a player with the username "8" on the server, they will be given operator permissions. Note that while Minecraft normally requires usernames to be 3 characters long, some accounts with shorter name lengths were created before this restriction.

The version that can be demonstrated to be non-deterministic without one of these usernames or risk of giving a user operator permissions is here:

me @r

Displays a message to everyone, the message being the username of a random player. The op command only takes a string literal, not any script that returns a string.

The me command wouldn't really work for the first example, it would display "<your-username> 8". When run from a command block, it wouldn't be deterministic since all command blocks have the same "username" but running it from the chat interface would require the / for one extra byte.

Pavel

Posted 2016-11-30T20:19:41.190

Reputation: 8 585

So / is not included in the byte count? – Esolanging Fruit – 2016-12-01T05:36:10.693

11@Challenger5 The slash is optional in command blocks, not allowed in the server console, and mandatory in the chat interface. – Pavel – 2016-12-01T05:47:54.617

op @r does not actually work. Variable expansion is explicitly disabled in the op command. Instead that command ops a player with an (invalid) name of @r. – Pokechu22 – 2016-12-01T16:24:02.823

Try me @r instead, as /me does support variable expansion if you're OP (iirc) and thus you'll get a real random name. – Pokechu22 – 2016-12-01T16:26:01.390

@Pokechu22 thanks! Io change it when it get on a computer. – Pavel – 2016-12-01T17:32:57.533

2Actually, it should be 4 bytes + 2 blocks (Command block and redstone source), or 6 blytes – RudolfJelin – 2016-12-02T16:38:07.210

2@RudolphJelinek You can run it from the console without command blocks. – Pavel – 2016-12-02T17:10:56.003

@Pavel but thenn it's non-repetible (eg. you have to retype it every time, no memory), so it doesn't fit the rules. – RudolfJelin – 2016-12-03T08:59:11.853

1Another non-deterministic option would be help in a command block, which is 4 bytes (and doesn't require pirated games). – Pokechu22 – 2016-12-06T19:03:10.897

@ГригорийПерельман But then it needs a slash. – Feathercrown – 2017-04-03T16:56:00.613

If you count error output, anything (even nothing maybe?) in a command block would work, because it prints the current time at the beginning. – Sobsz – 2018-03-16T18:29:36.157

21

sh + procps, 1 byte

w

This is the shortest solution I'm aware of that works via calling into external executables. procps is the responsible package for reporting information about the current system state (ps and friends), and is installed on most Linux distributions by default; w is the shortest-named command in it, and returns information about the logged-in users, but also some nondeterministic information like uptime.

user62131

Posted 2016-11-30T20:19:41.190

Reputation:

21

JavaScript, 4 bytes

Date

A function which returns the current date/time. I think this is the shortest it will get...

Explanation

Since this seems to be causing a lot of confusion as to why it's valid, I'll try to explain.

In JavaScript, a function entry is valid if it can be assigned to a variable and called like a function. For example, this function is a valid entry:

function(){return Date()}

Because it is a function that can be assigned to a variable like so:

f=function(){return Date()}

And then run with f() as many times as necessary. Each time, it returns the current date/time string, which has been ruled non-deterministic by the OP.

This ES6 arrow function is also valid:

_=>Date()

It can be assigned with f=_=>Date(), then run with f() like the other one.

Now, here's another valid entry:

Date

Why? Because just like the other two entries, it can be assigned with f=Date and then called with f(), returning exactly the same thing as the other two. Try it:

var f = Date
<button onclick="console.log(f())">Run</button>

ETHproductions

Posted 2016-11-30T20:19:41.190

Reputation: 47 880

1Do you not need it to be Date() to invoke the function? – milk – 2016-11-30T21:00:48.093

4@milk Date is a function which, when called with no inputs, produces the current date/time. _=>Date() is a clearly valid entry which does exactly the same thing, so Date is a valid entry. – ETHproductions – 2016-11-30T21:06:15.800

1That makes sense. – milk – 2016-11-30T21:17:04.060

Also, Date is a constructor and can be used as new Date(). – Ismael Miguel – 2016-11-30T23:17:34.390

If you know in advance that it will produce the current date, isn't that deterministic? – WGroleau – 2016-12-01T03:35:56.430

@WGroleau Sort of, but the OP has explicitly allowed date functions. – ETHproductions – 2016-12-01T04:00:37.563

2Typing Date to the JavaScript console of my browser produces deterministic output, it always produces this: function Date() { [native code] }. You probably mean Date(), 6 bytes. – pts – 2016-12-02T17:51:03.327

1@pts That would be a snippet, not a function or even a full program. This is a function entry, i.e. you call the function to run it. It's exactly the same as _=>Date(). – ETHproductions – 2016-12-02T17:52:47.033

2if "date" above is ok than "malloc(8)" or "time(0)" would be ok in C too – RosLuP – 2016-12-02T21:45:44.537

1@RosLuP Date in JavaScript returns a function, just like n=>n. I don't believe malloc(8) returns a function, so it's either a full program or a snippet. – ETHproductions – 2016-12-02T22:01:32.580

yes they print the result and time(0) is just one number,... – RosLuP – 2016-12-02T22:16:58.753

1You need to actually call Date to get non-deterministic output. One of the rules is "the output must be displayed". How is this a valid entry? – suriv – 2016-12-02T22:21:20.290

@RosLuP I've added an explanation which should clarify things. – ETHproductions – 2016-12-02T22:29:50.567

1@suriv This is a function entry, which have been allowed by the OP. See explanation for more info. – ETHproductions – 2016-12-04T20:42:39.567

21

Inform 7, 6 bytes

x is y

This isn't a valid Inform 7 program, since neither "x" nor "y" has been defined. So this throws an error.

However, some of Inform 7's error messages—including this one—are randomized. So the text it prints is technically non-deterministic.

A few possible outputs include:

Problem. The sentence 'x is y' appears to say two things are the same - I am reading 'x' and 'y' as two different things, and therefore it makes no sense to say that one is the other: it would be like saying that 'Adams is Jefferson'. It would be all right if the second thing were the name of a kind, perhaps with properties: for instance 'Virginia is a lighted room' says that something called Virginia exists and that it is a 'room', which is a kind I know about, combined with a property called 'lighted' which I also know about.

Problem. The sentence 'x is y' appears to say two things are the same - I am reading 'x' and 'y' as two different things, and therefore it makes no sense to say that one is the other: it would be like saying that 'Adam is Eve'. It would be all right if the second thing were the name of a kind, perhaps with properties: for instance 'Land of Nod is a lighted room' says that something called Land of Nod exists and that it is a 'room', which is a kind I know about, combined with a property called 'lighted' which I also know about.

Problem. The sentence 'x is y' appears to say two things are the same - I am reading 'x' and 'y' as two different things, and therefore it makes no sense to say that one is the other: it would be like saying that 'Clark Kent is Lex Luthor'. It would be all right if the second thing were the name of a kind, perhaps with properties: for instance 'Metropolis is a lighted room' says that something called Metropolis exists and that it is a 'room', which is a kind I know about, combined with a property called 'lighted' which I also know about.

Problem. The sentence 'x is y' appears to say two things are the same - I am reading 'x' and 'y' as two different things, and therefore it makes no sense to say that one is the other: it would be like saying that 'Aeschylus is Euripides'. It would be all right if the second thing were the name of a kind, perhaps with properties: for instance 'Underworld is a lighted room' says that something called Underworld exists and that it is a 'room', which is a kind I know about, combined with a property called 'lighted' which I also know about.

Draconis

Posted 2016-11-30T20:19:41.190

Reputation: 561

7Even the error messages are verbose! – Destructible Lemon – 2016-12-01T22:15:05.447

12

Bash (procps-ng), 2 bytes

ps

$$ is also a solution.

Rɪᴋᴇʀ

Posted 2016-11-30T20:19:41.190

Reputation: 7 410

1If so, w is shorter and also comes from procps. – liori – 2016-12-01T02:48:01.307

1

You edited this into a duplicate of my answer.

– None – 2016-12-01T11:30:03.633

@ais523 oops, sorry. – Rɪᴋᴇʀ – 2016-12-01T14:57:42.593

11

Python 2, 11 bytes

print id(1)

Blue

Posted 2016-11-30T20:19:41.190

Reputation: 26 661

1That's the one I found. I had id(0), though. :) – mbomb007 – 2016-11-30T20:32:10.013

2I beat you, technically, since I'm the OP and found it before I posted the question. I didn't want to post the question and immediately post my shortest answer. – mbomb007 – 2016-11-30T20:33:06.557

11

Pyth, 2 bytes

O0

Explanation:

 0 0
O  Random float in [0, 1)

It's that, when O has 0 as its argument, it simply returns a random float between 0 and 1, exclusive.

Let's do it just for the heck of it!

Also, it seems that this can be sorta retro (thanks to 34718/mbomb007):

Dilbert: September 8, 1992


Pyth, 2 bytes

OT

Explanation:

 T 10
O  Random integer in [0, 10]

Try this boooooooooooooooring version instead >:(

Erik the Outgolfer

Posted 2016-11-30T20:19:41.190

Reputation: 38 134

5http://dilbert.com/strip/1992-09-08 – mbomb007 – 2016-12-02T21:54:31.367

10

PowerShell, 4 2 bytes

(crossed out 4 still looks like 4)

ps

This is the alias for Get-Process which will output the current process listing as a table, including handles, private memory, CPU time, etc.

Execute it via something like the following:

C:\Tools\Scripts\golfing>powershell.exe "ps"

AdmBorkBork

Posted 2016-11-30T20:19:41.190

Reputation: 41 581

1I have to admit, I checked to see if it was actually crossed out. You really can't even tell. – Carcigenicate – 2016-12-01T00:25:53.820

@Carcigenicate I can tell if it is crossed without selecting the text (Ubuntu 16.04.1, Chrome 54.0.2840.100). – Erik the Outgolfer – 2016-12-01T19:38:04.670

Visible on android as well, though not clearly :p – tomsmeding – 2016-12-01T23:03:31.270

It looks fine in the iOS app. – Mateusz Piotrowski – 2016-12-06T12:43:13.153

I don't have the rep to do it myself, but you could do 04 and strike it out. – Bobson – 2016-12-06T14:09:45.210

9

Zsh, 5 bytes

<<<$$

Prints PID.

betseg

Posted 2016-11-30T20:19:41.190

Reputation: 8 493

9

Commodore 64 Basic, 4 bytes

1S|0

PETSCII substitution: | = SHIFT+Y

The zero page of a Commodore 64 is an area of 256 bytes of memory that can be accessed faster than the rest of RAM. Consequently, programs (such as the BASIC interpreter) use it for frequently-accessed data, and the CPU itself stores some of its internal state here. The contents are subject to change without notice.

The BASIC program above, ungolfed, is 1 SYS 0, ie. transfer execution to memory location 0. This starts executing the zero page as code. Normally, when the BASIC interpreter starts running a program, the first 16 bytes are

2F 37 00 AA  B1 91 B3 22
22 00 00 4C  00 00 00 00

so SYS 0 would execute the following

00: ROL-AND $37,A  - Undocumented opcode: rotate the value at memory location 0x37 left, and store the result in the accumulator
02: BRK            - Call the interrupt vector

The overall result is to output the BASIC READY. prompt and return control to the user. However, memory location 0x00 is the CPU's I/O direction register, and memory location 0x01 is CPU's I/O address register. If you've done something that changes these before running the program, the results can be unpredictable, ranging from outputting garbage to locking up the computer (the 0x22 usually contained in memory location 0x07, if executed as an instruction, is an undocumented HALT opcode).

Alternatively, a more reliably unpredictable program is the four-byte

1?TI

Prints the elapsed time, in jiffies (1/60 of a second), since system power-on.

Mark

Posted 2016-11-30T20:19:41.190

Reputation: 2 099

8

05AB1E, 2 bytes

žd

Try it online!

Outputs current microseconds from the executing machine's internal clock.

Or you could do something like this...

05AB1E, 3 bytes

A.r

Try it online!

Outputs a randomly shuffled lower-case alphabet.

Or this also works:

A.R

Try it online!

Outputs a random letter from the alphabet.

Or this also works, and is cooler:

05AB1E, 9 bytes

"ž"A.RJ.V

Try it online!

Outputs randomly one of these:

ž 23  > ža           push current hours
        žb           push current minutes
        žc           push current seconds
        žd           push current microseconds
        že           push current day
        žf           push current month
        žg           push current year
        žh           push [0-9]
        ži           push [a-zA-Z]
        žj           push [a-zA-Z0-9_]
        žk           push [z-aZ-A]
        žl           push [z-aZ-A9-0_]
        žm           push [9-0]
        žn           push [A-Za-z]
        žo           push [Z-Az-a]
        žp           push [Z-A]
        žq           push pi
        žr           push e
        žs           pop a, push pi to a digits (max. 100000)
        žt           pop a, push e to a digits (max. 10000)
        žu           push ()<>[]{}
        žv           push 16
        žw           push 32
        žx           push 64
        žy           push 128
        žz           push 256

Magic Octopus Urn

Posted 2016-11-30T20:19:41.190

Reputation: 19 422

8

C, 25 21 bytes

Thanks to pseudonym117 for saving 4 bytes.

main(i){putchar(&i);}

Compiled with gcc -o test lol.c (yeah I'm quite original with my file's name...), and ran with ./test.

It does what it says: prints the character corresponding to the memory address of i, which is defined at runtime, so it should be non-deterministic.

Paul Picard

Posted 2016-11-30T20:19:41.190

Reputation: 863

>

  • Can you skip the & as the value of a variable on the stack isn't defined? 2. You have a constant number of things on the stack, so is the memory address if i constant?
  • < – Riley – 2016-11-30T22:14:54.443

    you can change from printf to putchar and save a few bytes (because you dont need a format string) – pseudonym117 – 2016-11-30T22:17:31.213

    @Riley If I skip the &, it will always print 1. It should be undefined behavior though, but on my computer it kept printing 1. The address is not constant, but I cant tell if it's due to the program being executed in a different memory location each time, or if it's due to undefined behavior as well (my C knowledge isn't too great) – Paul Picard – 2016-11-30T22:33:58.513

    @pseudonym117 If I were to put putchar(&i), it would output ? most of the times, because &i will not correspond to any char. – Paul Picard – 2016-11-30T22:36:39.460

    you said exactly the point of the challenge - MOST of the time. not all of the time. – pseudonym117 – 2016-11-30T22:39:39.743

    Ah true, brainfarted. Thanks! – Paul Picard – 2016-11-30T22:43:06.407

    2i becomes what's normally called argc, so you're right, it will always be 1 unless there are more arguments. I can't believe I didn't rememeber that. I'm still not sure why the location changes, but if it works it works. – Riley – 2016-11-30T23:05:26.790

    1

    It changes on modern operating systems due to ASLR, a security feature designed to make it harder for exploits to guess addresses. You'll get a consistent result on some older OSes.

    – None – 2016-12-01T01:03:32.623

    1You can save a little by replacing putchar with return – ceilingcat – 2016-12-02T05:15:59.867

    1On modern compilers with warnings for not declaring the type of a parameter, you could do: main(){printf("%d");} – Myria – 2016-12-07T20:23:24.220

    8

    BrainfuckX and small s.c.r.i.p.t. (etc) polyglot - 2 bytes

    ?.
    

    ? - Randomize the value in the current cell

    . - Send current cell to stdout

    wyldstallyns

    Posted 2016-11-30T20:19:41.190

    Reputation: 401

    7

    Python 2, 29 bytes

    import os
    print os.urandom(9)
    

    Sadly not the first time writing code on a smartphone.

    Pavel

    Posted 2016-11-30T20:19:41.190

    Reputation: 8 585

    6

    Perl, 5 bytes

    say$$
    

    Outputs the process ID and a newline.

    user62131

    Posted 2016-11-30T20:19:41.190

    Reputation:

    6

    Ruby, 3 bytes

    p$$
    

    Try it online!

    Prints the process ID.

    Martin Ender

    Posted 2016-11-30T20:19:41.190

    Reputation: 184 808

    1$. would also work Nice approach though :) – Jatin Dhankhar – 2016-12-26T15:56:23.227

    5

    Pyke, 1 byte

    C
    

    Try it here!

    Outputs the current time

    Blue

    Posted 2016-11-30T20:19:41.190

    Reputation: 26 661

    1I'm fairly certain this is deterministic. – Rɪᴋᴇʀ – 2016-11-30T20:33:33.077

    @EasterlyIrk in a deleted comment mbomb said this was ok – Blue – 2016-11-30T20:34:07.237

    Oh, okay. Seems deterministic to me, but OP rules. – Rɪᴋᴇʀ – 2016-11-30T20:35:03.983

    In my edit history I had a 3 byte version with proper randomness – Blue – 2016-11-30T20:35:36.393

    @EasterlyIrk If the current time is deterministic, then so are pseudo-random numbers, since that's what they're seeded with. The goal is not "randomness". The goal is non-determinism. – mbomb007 – 2016-11-30T20:35:41.917

    @mbomb007 oh, true. forgot about that. – Rɪᴋᴇʀ – 2016-11-30T20:36:22.807

    5

    Groovy, 9 bytes

    {print{}}

    Outputs:

    Script1$_run_closure1@2c8ec01c

    Because it outputs the memory address of the closure it is non-deterministic.

    Magic Octopus Urn

    Posted 2016-11-30T20:19:41.190

    Reputation: 19 422

    And I thought Kotlin was the way to the shortest possible JVM solution. – F. George – 2016-11-30T23:33:09.540

    Trying to put this into a file and running groovy Script1.groovy, I get an error: Ambiguous expression could be either a parameterless closure expression or an isolated open code block;. How do I use this? – Paŭlo Ebermann – 2016-12-04T01:45:36.237

    Assign it to a closure variable, then call it. – Magic Octopus Urn – 2016-12-05T05:14:26.450

    5

    PHP, 12 bytes

    <?=uniqid();
    

    Outputs a unique ID 583f4da627ee3 based on the current time in microseconds.

    Mario

    Posted 2016-11-30T20:19:41.190

    Reputation: 3 043

    <?=time(); <-- 10 bytes. – Ismael Miguel – 2016-11-30T23:23:50.213

    @IsmaelMiguel uniqid() is 1'000'000 times more undetermined than time() ;) – Mario – 2016-11-30T23:40:22.180

    I'm not saying the oposite. But proposing another answer. You're free to pick that one. – Ismael Miguel – 2016-11-30T23:45:07.067

    @IsmaelMiguel someone else gave the same answer already... – Mario – 2016-11-30T23:46:44.997

    5

    Borland C on Windows, 12 bytes

    m(){puts();}
    

    I rewrote it because they say is possible to use one function. Compiler has not check the argument so compile it; but puts see one address 'nobody' know and begin to print what point that address until find the byte 0x00. It could be not ok if that address is out of memory reserved to program but here print something

    RosLuP

    Posted 2016-11-30T20:19:41.190

    Reputation: 3 036

    This doesn't give nondeterministic output, it just segfaults every time. – cat – 2016-12-01T14:26:59.977

    Alternatively, if you get something other than a segfault, what compiler ?? – cat – 2016-12-01T14:35:42.793

    @cat it is one Borland C compiler + Windows7 Os. In how I see: above code gets the address top of stack (where in this case there is the address to return in function main() )and read from that address inside main space code... So it depend to compiler output. But I don't know 100% ... It is possible code space is not readable in your Os and from this => seg fault – RosLuP – 2016-12-01T14:53:17.027

    I've edited your answer to include more information about the environment – cat – 2016-12-01T14:56:19.057

    Thanks, for doing something better why not "main(){printf("%p");}" I count 20 characters; this would be portable and would print the top of the stack address (if I see right) – RosLuP – 2016-12-01T15:08:55.647

    Yeah, that also seems to work with GCC although a byte longer – cat – 2016-12-01T15:14:14.373

    1

    @RosLuP: It would just print whatever garbage was in stack memory (or in the second arg-passing register, for x86-64 and most RISC calling conventions that pass the first few args in registers). It would not print the address of the stack. In x86-64, it would be somewhat likely to print argv, since the compiler would probably call printf with main's second arg still in that register. That's exactly what happens with gcc6.2 targeting Linux: See the source+asm on the Godbolt compiler explorer: main doesn't touch RSI before call printf.

    – Peter Cordes – 2016-12-06T14:42:39.940

    1@RosLuP: argv is on the stack, but not at the very top. Its address is affected by stack ASLR, though, so that works. This would work less well with -m32. You'd probably always get zero, since main has to keep the stack aligned so the stack slot above the format string may be fresh stack memory that has never been touched (and is probably always zero, since the kernel avoids info leaks by zeroing pages instead of giving user-space pages full of old data). – Peter Cordes – 2016-12-06T14:47:27.413

    5

    C89 with GCC/Clang, 20 bytes

    The other C solution just segfaults every time when built with GCC or Clang. This, though.

    main(n){puts(&n+1);}
    

    Which looks like:

    $ for _ in `seq 1 50`; do ./test_89; done
    ���z�U
    �VW��U
    �F��U
    �v�f2V
    ��FV
    ���*=V
    �6���U
    �20wU
    ��
    �+V
    �6
       �U
    ��V�uU
    �v��V
    ���K�U
    ��7�qU
    �6S�jU
    �&�WU
    ��wV
    ��6l�U
    ���U
    �F�ߨU
    �f���U
    ���s7V
    �f��?V
    ��;B�U
    �;��U
    ��GV
    �� ��U
    �vKV
    �V?]wU
    �����U
    ��.�U
    �v"�XU
    ��uhpU
    ��LD�U
    �����U
    �6X�U
    ��M�.V
    �69��U
    ��ԤV
    ���U
    ����U
    �vx4.V
    �֝+xU
    �F��U
    �֤BQV
    ��#�U
    ���1^U
    ����sU
    ��4�U
    ��AݗU
    

    Quite a lot of unprintable junk but it's nondeterministic!

    cat

    Posted 2016-11-30T20:19:41.190

    Reputation: 4 989

    why "main(n){puts(&n+1);}" and not "main(n){puts(&n);}"? – RosLuP – 2016-12-02T22:23:52.143

    @RosLuP Your second option, which seems obvious to the casual observer, gives the byte at the value of n (when n is 1, putsing its address gives 1, and when n is 2, putsing its address gives 2). Adding 1 to the address of n, which should point to a 4-byte wide int, gives a junk address with a junk value stored there with a very certain number of bytes until the next NUL byte. This behaviour is reproducible between GCC and Clang and completely beyond me. I think I'll go ask on StackOverflow. – cat – 2016-12-02T22:30:53.740

    i read "puts(&n)" in this way: it give to puts the address of n, suppose that n=0x01020304 puts would print converted in chars 04 03 02 01 or reverse of that – RosLuP – 2016-12-02T22:41:27.287

    1Remember your n is still initialized with what's normally called argc which is 0 in your general test case, so with &n, puts gets a quite deterministic pointer to a '\0' byte resulting in an empty string (assuming pointer size == integer size and all that stuff). &n+1 however is the address of what's normally called argv (at least on ABIs that pass parameters on the stack in reverse order instead of registers, and with a stack that grows from high to low addresses), which, assuming ASLR, should be a different pointer every time. – Guntram Blohm supports Monica – 2016-12-05T15:11:30.713

    @GuntramBlohm You're right and that's very interesting, although for me pointers are 8 bytes and ints are 4 bytes. – cat – 2016-12-05T15:29:12.417

    5

    Emotinomicon, 15 bytes

    Explanation:

    ⏬
          push 0. Stack: [0]
          push 1. Stack: [1]
          random[pop;pop]. Stack: [1 or 0]
          ⏬output
    

    Roman Gräf

    Posted 2016-11-30T20:19:41.190

    Reputation: 2 915

    The language's name is Emotinomicon – acrolith – 2016-12-02T18:46:47.613

    @daHugLenny How did I missed that :) – Roman Gräf – 2016-12-02T19:48:37.227

    5

    Baby Language, 0 bytes

    
    
    

    I didn't submit this originally because I thought it postdated the question. I was wrong; the language did have an interpreter created in time. It's also probably the least cheaty 0-byte solution I've seen (given that a 0-byte program is specified to do exactly what the program asks, and not for the purpose of cheating on golfing challenges).

    Baby Language is specified to ignore the program it's given and do something at random. (The interpreter linked on the Esolang page generates a random legal BF program and runs it.) That seems like a perfect fit for this challenge.

    user62131

    Posted 2016-11-30T20:19:41.190

    Reputation:

    4

    Jelly, 2 bytes

    9X
    

    Idk if this works. I've never done anything in jelly before, and I'm on my phone right now.

    Int from 0 to 9.

    Pavel

    Posted 2016-11-30T20:19:41.190

    Reputation: 8 585

    1Prints 09 every time for me. 9X works though – ETHproductions – 2016-11-30T20:57:00.803

    @ETHproductions Thanks. That was my original answer, I edited because I thought it didn't work. :/ I can't test things on my phone, so I had to go with what looked right from never using the language before. – Pavel – 2016-11-30T21:28:10.977

    It's [1, 9], not [0, 9]. Also, you can do ⁹X to do [1, 256] for the same bytecount. – Erik the Outgolfer – 2016-12-02T21:29:54.860

    4

    ><>, 4 3 bytes

    (crossed out 4 still looks like 4)

    0nx
    

    Try It Online!

    Outputs some amount of 0's.

    On an empty stack n throws an error and terminates the program. x chooses a random direction for the stack pointer. This means that for each 0 printed, there is a 50% chance for the program to exit.

    Blue

    Posted 2016-11-30T20:19:41.190

    Reputation: 26 661

    Oh, 0xn didn't work because it pushes two zeros to begin with. Both 0nx and xn0 would work. – Martin Ender – 2016-11-30T21:13:38.523

    I realised that - if go left first time, end up with 0 printed and 0 on the stack. The same happens for right, meaning that that program was deterministicly infinitely 0 output – Blue – 2016-11-30T21:16:33.927

    @BlueEyedBeast This is a nice one, my version differs a little bit but same bytes; "ox – Teal pelican – 2016-12-01T09:46:38.423

    4

    Japt, 1 byte

    Ð
    

    Test it online!

    How it works

    When Japt is compiled to JavaScript, it replaces Ð with new Date(. The close-paren is automatically added by the interpreter, and the result of the last expression is automatically printed, so this prints the current date/time.

    An alternate solution would be Mr, which uses Math.random. Japt also has the variable K set to Date (no clue why I did that, it's almost entirely useless), which I guess makes K a valid function entry.

    ETHproductions

    Posted 2016-11-30T20:19:41.190

    Reputation: 47 880

    4

    Mathematica, 6 bytes

    Date[]
    

    Pretty self-explanatory. (This function was superseded by DateList[] in later versions, but Date[] still runs.)

    For 8 bytes one can also use Random[] (itself a legacy function).

    Greg Martin

    Posted 2016-11-30T20:19:41.190

    Reputation: 13 940

    1For 10 characters, you can us $ProcessID. – Michael Stern – 2016-12-01T03:07:49.030

    Aha, nice idea! The 7-byte $System is the shortest one I could find. – Greg Martin – 2016-12-01T09:25:19.443

    4

    MATL, 1 byte

    r
    

    Uniform random number generator between 0 and 1. The seed is randomly set for each execution of the program. Try it online!

    Luis Mendo

    Posted 2016-11-30T20:19:41.190

    Reputation: 87 464

    3

    Same exact solution and explanation works in Pip.

    – DLosc – 2016-12-01T03:34:49.413

    4

    C#, 36 22 bytes

    a=()=>a.GetHashCode();
    

    Yay.

    Yodle

    Posted 2016-11-30T20:19:41.190

    Reputation: 2 378

    Why the braces and the return? Just make it ()=>Environment.TickCount; – Dennis_E – 2016-12-01T15:18:43.603

    @Dennis_E Yeah I didn't know you could do it like that for one liners, thanks! – Yodle – 2016-12-01T15:37:00.243

    1You beat the javas :[ Have an upvote. (verbose language users like us gotta stick together) – Poke – 2016-12-01T15:39:22.957

    1@Poke :D I'm trying to figure out if there's an even shorter way, but so far most of the other things for the function don't return different things each run. Although doing a.Target returns nondeterministic+<>c__DisplayClass0_0 which has 0_0 in it, which is cool. – Yodle – 2016-12-01T15:41:39.677

    Wouldn't DateTime.Now also fit the requirements? It produces different output at different times and is shorter than Environment.TickCOunt() or a.GetHashCode(). – Snowfire – 2016-12-02T07:59:34.457

    @Snowfire ()=>System.DateTime.Now; is 2 bytes longer unfortunately, but yes it would work if you didn't have to include System. – Yodle – 2016-12-02T14:48:29.763

    @Yodle Oh yes, of course. I didn't think about that, my fault. – Snowfire – 2016-12-02T14:52:57.393

    4

    C++, 26 19 Bytes

    std::cout<<new int;
    

    Returns a different memory address each time it's run

    Snowfire

    Posted 2016-11-30T20:19:41.190

    Reputation: 181

    What does the * do? – Pavel – 2016-12-02T08:21:40.567

    @Pavel int* means a pointer to an integer. – mbomb007 – 2016-12-02T14:39:06.477

    Isn't this just a snippet? A program would need a main function... – Mega Man – 2017-03-05T12:56:23.510

    3

    Cubix, 3 bytes (non-competing)

    @OD
    

    Outputs a random positive number of zeroes. Non-competing because I added D just a few minutes ago. Before it was added, there was absolutely no way to randomize anything in Cubix.

    Test it online!

    How it works

    Before the code is run, it's padded with no-ops . and formed into a cube net. Here's what the net for this particular program looks like:

      @
    O D . .
      .
    

    Now the code is run, starting on the left-most face and heading to the right.

    First, O outputs the top item on the stack as a number. At the beginning of the program, the stack is an infinite fount of zeroes, so this prints 0.

    Next, D sends the IP (instruction pointer) in a random direction: possibly up to the @ which ends the program, and possibly back to the O which prints another 0. This continues until whenever the IP hits the @.

    @DO and OD@ also work, each printing zero or more zeroes.

    ETHproductions

    Posted 2016-11-30T20:19:41.190

    Reputation: 47 880

    3

    x86/amd64 machine language (Pentium or higher), 3 bytes

    0:       0f 31                   rdtsc  
    2:       c3                      retq
    

    This uses the RDTSC instruction that may not be available on older processors. To test, try the following C program on Linux x86/amd64

    #include <stdio.h>
    int main(){
      for( int i = 0; i < 10; i++ ) {
        printf( "%d\n", ((int(*)())"\x0f\x31\xc3")() );
      }
    }
    

    Or try it on Ideone.

    ceilingcat

    Posted 2016-11-30T20:19:41.190

    Reputation: 5 503

    1To clarify how the value is returned; RDTSC loads the most significant 32 bits into edx, and the least significant 32 bits into eax. The convention for returns in this matchine code is that an int-sized return value is stored in eax, so the function's return value is suitably nondeterministic. – None – 2016-11-30T21:38:13.663

    3

    Minecraft, 2 bytes

    /r
    

    Must be written into chat when playing on multiplayer servers. Will throw an error if you hadn't messaged (/tell) anybody recently. Otherwise, shows both players a random message.

    Note: I'm not really sure if this is a legit solution :)

    Minecraft, 4 bytes (+2 blocks)

    help
    

    Ties with another Minecraft answer from @Pavel

    This is based on Minecraft's Easter egg:

    When you type help or /help in a Command block, a random message starting with "Searge says:" is displayed, for example "Searge says: Ask for help on twitter". Here is a full list of messages.

    RudolfJelin

    Posted 2016-11-30T20:19:41.190

    Reputation: 853

    3

    Lua, 9 bytes

    print({})
    

    Outputs the internal address of the Lua table object:

    table: 0x2370ab0
    

    If you're running from the interactive interpreter, you can use just 3 bytes:

    > ={}
    table: 0x23719c0
    

    Myria

    Posted 2016-11-30T20:19:41.190

    Reputation: 154

    3

    C, 19

    f(a,b){putchar(b);}
    

    In C the second declared variable in a function's arguments is random based on memory. Assuming the arguments were not actually declared, i.e. you just called f();.

    So this function can be simply called with no input-arguments. That is, just: f(); and the output will be a random character.

    Try it online! (Note: output might be an unprintable character, run the program a few times to see variation, you should get more printable characters than non-printable characters)

    Albert Renshaw

    Posted 2016-11-30T20:19:41.190

    Reputation: 2 955

    3

    C (gcc), 18 bytes

    f(){printf("%d");}
    

    This one may be difficult to test since TIO will give you a cache hit. Just add some whitespace and try it again.

    Try it online!

    Bijan

    Posted 2016-11-30T20:19:41.190

    Reputation: 781

    3

    INTERCAL, 0 2 bytes (0+2 for command flag)

    Try it online! (I don't know if the TiO compiler reproduces this functionality correctly)

    This is not a valid INTERCAL program, so attempting to run it gives Error 778 - UNEXPLAINED COMPILER BUG. However, when INTERCAL is run without the -b command flag, there is a small chance that it doesn't run and throws Error 774 - RANDOM COMPILER BUG. So if errors count as output for this challenge, then INTERCAL might actually be good for something!

    INTERCAL, 17 bytes

    DO %9 READ OUT #5
    

    Try it online!

    This is a more standard approach. It has 9% chance of printing V before terminating (with an error, but it gives the output, so who cares?)

    KSmarts

    Posted 2016-11-30T20:19:41.190

    Reputation: 1 830

    Compiler flags have to be included in the byte count. See meta post.

    – mbomb007 – 2017-10-06T16:59:42.627

    @mbomb007 It doesn't use any compiler flags--that's the whole point. The "RANDOM COMPILER BUG" occurs when a program is run without the -b flag. – KSmarts – 2017-10-06T18:22:49.990

    Any difference from the standard flags counts. So if removing the flag is the difference, that's a one-byte difference. – mbomb007 – 2017-10-06T19:08:31.727

    2@mbomb007, although any sensible person would run the INTERCAL compiler with the -b option, a sensible person wouldn't be using INTERCAL in the first place. – Mark – 2017-10-06T22:07:28.310

    3

    Retina, 3 bytes

    ?&`
    

    Try it online!

    Yay, Retina can finally compete in challenges that require randomness! \o/

    Explanation

    ?& is a compound stage which executes its child stage with a 50% probability. That child stage is itself a Count stage, which counts the number of empty matches in the empty input (1). So if the child stage is run, the result is 1, if it isn't, then the empty input remains unchanged and we get an empty string.

    A fun alternative for the same byte count would be:

    ?+`
    

    Try it online!

    This one uses a random loop (which uses a coin toss before each iteration to decide whether to continue). This one has a 50% chance of printing an empty string, 25% of printing 1 (one iteration) and a 25% chance of printing 2 (two or more iterations).

    Martin Ender

    Posted 2016-11-30T20:19:41.190

    Reputation: 184 808

    3

    Lost, 7 bytes

    @%"
    ///
    

    Try it online!

    Since Lost starts the pointer in a random place facing a random direction, it's refreshing not making the output deterministic for once. I think this is the optimal solution since you need the @ and % in order to end the program, the " to push stuff to the stack at random, and the /// to avoid infinite loops.

    Jo King

    Posted 2016-11-30T20:19:41.190

    Reputation: 38 234

    2The challenge does not require the program to halt. Thus @% alone will work. This either loops forever outputting nothing or halts and outputs a newline. – Post Rock Garf Hunter – 2018-08-23T03:20:10.207

    2

    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())

    F. George

    Posted 2016-11-30T20:19:41.190

    Reputation: 317

    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 – 2016-12-04T19:31:42.803

    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 – 2016-12-05T04:23:51.253

    Just out of curiosity, what does it output on your machine? – Paŭlo Ebermann – 2016-12-05T18:02:20.327

    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 – 2016-12-05T20:29:22.430

    2

    PHP, 10 Byte

    <?=time();
    

    This prints the current Unix time which – of course – isn't random but changes when you call the program several times. The output I just got is 1480548602.

    UTF-8

    Posted 2016-11-30T20:19:41.190

    Reputation: 153

    Welcome to PPCG! Nice answer, by the way. – Erik the Outgolfer – 2016-12-02T21:33:28.503

    2

    APL, 2 bytes

    ?9
    

    This uses APL's roll (?) operator. The program prints a pseudo-random number between 1 and 9.

    ren

    Posted 2016-11-30T20:19:41.190

    Reputation: 189

    Also works in J. – Conor O'Brien – 2016-12-01T11:27:58.673

    2Looks deterministic to me, except if ⎕RL≡⍬2 or after executing ⎕RL←0. A safer bet is ⎕TS or ⎕AI. – Adám – 2016-12-05T23:43:51.683

    1

    Update: Your code has now become non-deterministic, as the default has become to ask the OS for a random number. Try it online!

    – Adám – 2018-02-02T09:30:57.847

    2

    Brachylog, 3 bytes

    9$?
    

    Try it online!

    Explanation

    $? 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.

    Fatalize

    Posted 2016-11-30T20:19:41.190

    Reputation: 32 976

    2

    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
    

    mbomb007

    Posted 2016-11-30T20:19:41.190

    Reputation: 21 944

    2

    PHP 10 bytes

    <?=rand();
    

    Prints a random number between 0 and getrandmax(). Which may vary based on what computer it's run on.

    aslum

    Posted 2016-11-30T20:19:41.190

    Reputation: 251

    2

    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.

    mbomb007

    Posted 2016-11-30T20:19:41.190

    Reputation: 21 944

    2

    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.

    Harry

    Posted 2016-11-30T20:19:41.190

    Reputation: 1 189

    2

    CJam, 2 bytes

    et

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

    Yeah, that one. et is a single built-in that returns the array [YYYY M D h m s ms W Z], printed as YYYYMDhmsmsWZ.

    Erik the Outgolfer

    Posted 2016-11-30T20:19:41.190

    Reputation: 38 134

    2

    Ruby, 14 bytes

    p ?..object_id
    

    Returns object id of the string '.'

    Vasu Adari

    Posted 2016-11-30T20:19:41.190

    Reputation: 941

    2

    TI-Basic, 2 bytes

    Very similar to this answer. The getTime token is two bytes and is located at EF 0A.

    getTime
    

    Timtech

    Posted 2016-11-30T20:19:41.190

    Reputation: 12 038

    rand is 1 byte. – bb94 – 2019-03-19T00:18:20.737

    1@bb94 "A pseudo-random number generator that always has the same seed does not count." – Timtech – 2019-04-02T00:34:27.477

    2

    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
        } 
    }
    

    Metoniem

    Posted 2016-11-30T20:19:41.190

    Reputation: 387

    2

    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
    

    Skidsdev

    Posted 2016-11-30T20:19:41.190

    Reputation: 9 656

    2

    Wumpus, 4 bytes

    UFO@
    

    Try it online!

    Outputs a uniformly random choice of 2, 5 or 8.

    Explanation

    Apart from a regular stack, Wumpus also has 20 registers which are arranged around the faces of an icosahedron. You can imagine the icosahedron as a d20 resting on a table: the face touching the table is the "active" face (i.e. the register that can currently be interacted with). Also, every face has an index from 1 to 20. Initially, the active face is 1 and the three adjacent faces are 2, 5 and 8 (see the README in the Wumpus repo for the full net).

    U   Randomly tip the icosahedron onto one of the three adjacent faces, i.e.
        change the active faces to either 2, 5 or 8.
    F   Push the index of the currently active face.
    O   Output as a decimal integer.
    @   Terminate the program.
    

    Alternatively:

    DFO@
    

    This one completely randomises the orientation of the icosahedron, so it prints a random number from 1 to 20, inclusive.

    Martin Ender

    Posted 2016-11-30T20:19:41.190

    Reputation: 184 808

    5Little-known fact: This works in Mathematica too! The code reads as UFO at and so it grabs the location of the nearest UFO and prints it, something which is obviously non-deterministic. – Esolanging Fruit – 2018-02-12T03:45:03.100

    2

    Intercept 1.1, 37 bytes


    Prints newlines to the terminal. You'll probably have to leave this one overnight, as there is a delay of 5-15 minutes (it's random!) between each newline. Note that while you can determine what is being printed, you can't determine how often it's being printed.

    Input is marked with a >>. The command prompt is the empty >>.

    Assuming a system with only TZ_INFECT installed...

    
    >> malware bm bitminer
    creating bm (bitminer)
    ... wait a minute ...
    
    finished creating bm (bitminer)
    >> software install 1
    Success
    bm installed
    
    ...wait...
    (newlines)
    
    
    
    
    
    
    
    
    >>
    

    Note that I'm using a custom client that prefixes [BROADCAST] to all broadcast events.

    How???

    TZ_INFECT is Intercept's malware generator. We can generate a bitminer by running malware <name> bitminer. This will create a new piece of software with the given name of type bitminer

    We then install the bitminer: software install <index>, where index is the 0-based index of the software as given by software list. This is why I made sure the only piece of software on the system was the malware generator. This places our new bitminer at index 1.

    There is a bug in the implementation of bitminer that results in an empty broadcast event to be sent to the client whenever bits are generated. Since bits are generated at random intervals, the broadcasts are sent at random intervals. Voilia, non-deterministic output!

    Note: the newlines are harder to detect using the official game client, but you can see them by running a command and watching the newlines slowly push the resulting output off the screen.

    Screenshots coming in a few hours while I wait for the output.
    After 20 minutes (the [BROADCAST] is a newline): Intercept

    After 2 days:

    Intercept

    Benjamin Urquhart

    Posted 2016-11-30T20:19:41.190

    Reputation: 1 262

    2

    Keg, 1 byte

    ~
    

    This pushes a random number onto the stack and then outputs that number by default.

    user85052

    Posted 2016-11-30T20:19:41.190

    Reputation:

    Polyglots with Volatile – Lyxal – 2019-10-25T22:21:52.457

    Volatile doesn't have implicit output. – None – 2019-10-25T22:49:01.990

    1

    Wirefunge - 2 bytes

    ¿>
    

    ¿ - Randomized output every iteration

    > - When it rises, puts 1-8 on stdout

    wyldstallyns

    Posted 2016-11-30T20:19:41.190

    Reputation: 401

    1

    Clojure, 4 bytes

    rand
    

    The obvious answer. rand is a core function that returns a floating-point number between 0 and 1 (exclusive) when called without any arguments.

    I don't think it gets any shorter than this in Clojure.

    Carcigenicate

    Posted 2016-11-30T20:19:41.190

    Reputation: 3 295

    1

    Perl 6, 13 bytes

    put Bool.pick
    

    Brad Gilbert b2gills

    Posted 2016-11-30T20:19:41.190

    Reputation: 12 713

    1

    Swift 3, 13 bytes

    print(Date())
    

    Daniel

    Posted 2016-11-30T20:19:41.190

    Reputation: 6 425

    1

    Marbelous, 5 bytes

    FF
    ??
    

    Prints a single random byte. FF creates a marble with value 255. That marble falls through the random number generator ?? which replaces the marble's value with a random value between 0 and 255 inclusive. When the marble falls off the bottom of the board, it gets printed to STDOUT as a byte.

    Martin Ender

    Posted 2016-11-30T20:19:41.190

    Reputation: 184 808

    1

    R, 7 bytes

    The Student t Distribution

    rt(1,1)
    

    The Exponential Distribution

    rexp(1)
    

    Two options how to generate a random number with the shortest code.

    djhurio

    Posted 2016-11-30T20:19:41.190

    Reputation: 1 113

    1

    ForceLang, 11 bytes

    random.rand
    

    A function that, when called with no arguments, produces a random rational of the form n/2^80, where n is an integer on [0,2^80-1].

    (If you give it a positive integer argument m [which must be strictly less than 65536, not that you'll ever reasonably need to go nearly that high] it will produce a random rational of the form n/2^m, where n is an integer on[0,2^m-1])

    SuperJedi224

    Posted 2016-11-30T20:19:41.190

    Reputation: 11 342

    1

    Thue, 17 bytes

    a::=
    a::=~1
    ::=
    a
    

    Randomly prints either nothing, or the digit 1.

    SuperJedi224

    Posted 2016-11-30T20:19:41.190

    Reputation: 11 342

    1

    T-SQL 15 bytes

    print getdate()
    

    Nelz

    Posted 2016-11-30T20:19:41.190

    Reputation: 321

    1

    Minkolang v1.5, 4 bytes

    lhN.
    

    l pushes 10. h pushes a random integer from 0 to 10, N outputs it and . ends program. Simple, eh?

    Try it online!

    user41805

    Posted 2016-11-30T20:19:41.190

    Reputation: 16 320

    1

    Ceylon (on JVM), 22 bytes

    ()=>system.nanoseconds
    

    This turned out surprisingly difficult. At first I thought I cold use the .hash attribute of all objects (corresponds to Java's .hashCode() when running in the JVM), but it turns out that most objects I can write in a literal way have their .hash attribute overridden, returning a deterministic value.

    For example, [] (the empty tuple) or {} (the empty iterable) are both the same object, and which inherits List.hash, which returns 1 in this case. For strings (like ""), characters (c) or numbers (like 3 or 2.5) of course the hash needs to be deterministic, same for true and false (0, 99, 3, 1074003968, 1231, 1237, respectively).

    The base class Basic, which has the Java-like hash code implementation (assumedly based on the memory address?) is abstract, so I can't use Basic().hash (nor Object().hash – also abstract, and here even the method is not implemented). So let's create a new class, create an instance and take its hash code?

    class E() {}
    function f() => E().hash;
    shared void run() {
        print(f());
    }
    

    This always outputs 1116094714 whenever I execute this program. (Adding other statements which allocate memory before the print line changes the result – still deterministically, though.)

    Ceylon also supports anonymous classes as object expressions. Those can extend classes or implement interfaces and have own code, but the most minimal variant is just object{}:

    shared void run() {
        function f() => object{}.hash;
        print(f());
    }
    

    Still the same result 1116094714, though.

    Another idea was to use the hash code of a class or function reference. (Those are normal objects, I thought.) But trying to use run.hash (or f.hash) gives a compiler error:

    error: direct function references do not have members

    We can work around this by assigning this function reference first to a value, which will create an object of a (hidden) anonymous class:

    shared void run() {
        value x = run;
        value y = run;
        print([x.hash, y.hash]);
    }
    

    This prints two different values, but the same ones ([762384154, 690052870]) each time I run the program. Still deterministic.

    So, using any hash code will not bring us forward (and I suppose that the other JVM answers here with .hashCode() would have the same problem on my JVM implementation). Same with printing an object with the default .string implementation based on .hash.

    There is no random number facility in ceylon.language, so using either ceylon.random or Java's java.util.Random (or java.lang.Math.random()) needs an import, which increases the size more than I want to tolerate for a codegolf answer. Here is an example:

    import ceylon.random { ... }
    shared void run() {
        print(randomize{1,2});
    }
    

    So let's look at what we have in ceylon.language. There are four top-level objects which allow access to the environment:

    • operatingSystem – name, version, path/file separator, newline.
    • process – command line arguments, system properties, environment variables, input/output.
    • runtime – whether we are on JVM/JS/Dart, version info, and stuff like bit sizes. Nothing which will change between runs of the same program in the same VM.
    • system – ah, here we go. Beside locale, character encoding and time zone offset we also have:
      • milliseconds
      • nanoseconds

    Both will change with each call of a program, and the latter one is shorter.

    So here we have an anonymous function returning different values:

    () => system.nanoseconds
    

    If we want a named function, its definition can look like this:

    Object n()=>system.nanoseconds;
    

    (It actually returns Integer, but that is one character longer than Object.)

    Paŭlo Ebermann

    Posted 2016-11-30T20:19:41.190

    Reputation: 1 010

    1

    Shell, 2 bytes

    ps

    Explain: the PIDs returned are not going to be the same each time.

    Ronsor

    Posted 2016-11-30T20:19:41.190

    Reputation: 11

    1

    SmileBASIC, 6 bytes

    ?TIME$
    

    Prints the current time.

    12Me21

    Posted 2016-11-30T20:19:41.190

    Reputation: 6 110

    1

    tcl, 3

    Must be run on an interactive shell

    pwd
    

    Gets the current working directory.

    Or alternatively

    pid
    

    Gets the current process identifier

    Demo: Go to https://www.tutorialspoint.com/execute_tcl_online.php and in the green area, type

    tclsh
    

    Then type

    pwd
    

    and

    pid
    

    sergiol

    Posted 2016-11-30T20:19:41.190

    Reputation: 3 055

    1

    Alice, 4 bytes

    2Uo@
    

    Try it online!

    Prints a single byte, either 0x00 or 0x01, with 50% probability each.

    2    Push 2.
    U    Get a random integer in [0,1].
    o    Output that integer as a byte.
    @    Terminate the program.
    

    Martin Ender

    Posted 2016-11-30T20:19:41.190

    Reputation: 184 808

    1

    Fourier, 3 bytes

    9ro
    

    Outputs a random number from 0 to 9.

    Try it online!

    Beta Decay

    Posted 2016-11-30T20:19:41.190

    Reputation: 21 478

    1

    Braingolf, 2 bytes

    1r
    

    Pushes 1 to the stack, then pushes a random number between 0 and the last item on the stack (1). Implicitly prints the last item on the stack (the random number)

    Skidsdev

    Posted 2016-11-30T20:19:41.190

    Reputation: 9 656

    1

    Add++, 6 bytes

    The most random I could get for 6 bytes

    +9  Set the accumulator to 9
    R   Set the accumulator to a random integer between 0 and 9
    O   Output the result
    

    I could change R to R-9 to double the randomness for 2 extra bytes.

    caird coinheringaahing

    Posted 2016-11-30T20:19:41.190

    Reputation: 13 702

    1

    Taxi, 224 222 bytes

    Go to Heisenberg's: w 1 r, 3 r, 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery: s 1 r, 1 l.Pickup a passenger going to Post Office.Go to Post Office: n, 1 l, 1 r.Go to Taxi Garage: n 1 r, 1 l, 1 r.
    

    Prints a random number. The spec does not give any details on what number should be. The last statement can be omitted if you don't mind the code giving an error after printing the output.

    pppery

    Posted 2016-11-30T20:19:41.190

    Reputation: 3 987

    Can you link to the language, since this is not a well-known one? – mbomb007 – 2017-07-29T03:30:26.880

    1

    Chip, 2 + 3 = 5 bytes

    +3 bytes for -w

    g?
    

    Gives infinite-length output. Each byte of output is independent, and is either NUL \x00 or '@' \x40.

    There are eight equivalent Chip programs that are like this, from a? (which prints \x00 or \x01) to h? (which prints \x00 or \x80). g? is just the most visible option.

    For each of these programs, the letter a through h defines the index of a bit of the output, and ? produces a random value to set it to. The two elements may be provided in any order; they must only touch each other on a 2D plane.

    Try it online! The TIO includes the -cN flag. This flag is not necessary, but cuts off the program after N bytes. Try without the cutoff if you wish, but TIO's limit is at 128KiB.

    Phlarx

    Posted 2016-11-30T20:19:41.190

    Reputation: 1 366

    1

    Rust, 28 bytes

    fn main(){print!("{:p}",&1)}
    

    Try it online!

    Takes a reference to a temporary 1 and prints the address.


    Rust, 17 bytes

    fn main(){0-1u8;}
    

    Try it online! (requires the -A const_err compiler flag)

    This is a bit sketchier, and I'm not sure whether it counts. The non-deterministic output is to STDERR, and the non-determinism arises only based on the value of an environment variable.

    This program attempts to compute 0 - 1, where both integers have type u8 (the default is i32, which won't cause an overflow because it's signed). By default, Rust compiles the file in debug mode, in which arithmetic overflow causes a panic instead of wrapping. When a program panics, it will print a stack trace if the environment variable RUST_BACKTRACE is set to 1, hence the non-determinism.

    Esolanging Fruit

    Posted 2016-11-30T20:19:41.190

    Reputation: 13 542

    1

    Flobnar, 5 4 bytes

    -1 byte thanks to @JoKing

    0?.@
    

    Try it online!

    Esolanging Fruit

    Posted 2016-11-30T20:19:41.190

    Reputation: 13 542

    1

    Ink, 5 bytes

    {~a|}
    

    Try it online!

    Either outputs "a" or nothing.

    Sara J

    Posted 2016-11-30T20:19:41.190

    Reputation: 2 576

    1

    Perl 6, 7 bytes

    say now
    

    about now

    bb94

    Posted 2016-11-30T20:19:41.190

    Reputation: 1 831

    1

    Japt, 1 byte

    K
    

    Try it online!

    Cortex

    Posted 2016-11-30T20:19:41.190

    Reputation: 97

    Welcome to Japt! :) (and the site) If you weren't aware, there's an open bounty running for Japt solutions.

    – Shaggy – 2019-03-21T21:51:07.360

    1

    Trigger, 14 bytes

    ABAAA AAB    B
    

    Try it online!

    A                NOT the value of the A trigger, making it one
     B               NOT B
      AAA            Print "A"
          AAB        Go to the nearest B in the program. If it is the same distance, it picks it randomly. This can go to the NOT B command or go to the next B command, running the print A or ending the program, respectively.
    

    MilkyWay90

    Posted 2016-11-30T20:19:41.190

    Reputation: 2 264

    0

    Shellscript (as implemented by ttyrec), 0 bytes

    OK, here's a version of this idea that uses an interpreter that can actually be programmed with.

    The ttyrec command by default just passes everything it sees on standard input to a shell, and thus obeys our definition of a programming language (it's Turing-complete, because bash is; it's basically just an alternate front-end to bash, and so is basically a shellscript interpreter that can be used to program with). However, it also creates a file ttyrecord containing a recording of the shell's output, and that file starts with the current time, in binary (and is also affected in some ways by the system's CPU and swapping load, as it tries to separate the output into frames). Thus, it produces a file with nondeterministic content as output.

    user62131

    Posted 2016-11-30T20:19:41.190

    Reputation:

    I'm not using any commands. Shellscript is Turing-complete. At least one implementation of it produces nondeterministic output in addition to running the program given, thus you get the output you want even with no commands. Languages are defined by the interpreter here. – None – 2016-11-30T20:56:09.263

    (the above was in reply to a since-deleted comment that this wasn't valid due to not using commands) – None – 2016-11-30T21:03:15.953

    0

    JavaScript, 8 bytes

    Date.now
    

    This evaluates to a function whose return value is nondeterministic, and conveniently doesn't actually need to be bound to anything specific to work.

    Neil

    Posted 2016-11-30T20:19:41.190

    Reputation: 95 035

    Basically, this is the same as the Date answer. – Ismael Miguel – 2016-11-30T23:20:58.567

    @IsmaelMiguel I did have the idea of returning a builtin first; I just returned the wrong builtin. – Neil – 2016-12-01T00:31:13.980

    0

    Batch, 6 4 bytes

    time
    

    Needs to be run with <nul which is apparently permissible.

    Neil

    Posted 2016-11-30T20:19:41.190

    Reputation: 95 035

    This is what I was referring to: http://meta.codegolf.stackexchange.com/a/7172/34718

    – mbomb007 – 2016-12-01T14:28:26.157

    @mbomb007 Thanks, I wasn't aware of that. – Neil – 2016-12-01T14:34:39.733

    0

    QBIC, 4 bytes

    ?_r|
    

    This generates and prints a random number between 0 and 10. QBIC uses the classical RANDOMIZE TIMER at the start of execution to set the RNG.

    steenbergh

    Posted 2016-11-30T20:19:41.190

    Reputation: 7 772

    0

    Actually, 1 byte

    G
    

    Try it online!

    Good old rand(). In Python 3, 2500 random bits from the system's cryptographically-secure randomness source (getrandom() for Linux, /dev/urandom for *NIX, or CryptGenRandom for Windows) are used for the seed, falling back on the current UNIX time (as precisely as possible for the given platform - at minimum, 1-second precision) if such a source of randomness is not available.

    Mego

    Posted 2016-11-30T20:19:41.190

    Reputation: 32 998

    0

    Microscript II, 1 byte

    R
    

    Produces a random 64-bit float on [0,1).

    Another one-byte solution would be C, which produces a new continuation object, whose timestamp (which the reference implementation includes in its string representation) will be nondeterministic.

    SuperJedi224

    Posted 2016-11-30T20:19:41.190

    Reputation: 11 342

    0

    Microscript, 2 bytes

    r9

    Produces a random integer on [0,8]

    SuperJedi224

    Posted 2016-11-30T20:19:41.190

    Reputation: 11 342

    0

    Mouse2002, 7 bytes

    &RAND !
    

    cat

    Posted 2016-11-30T20:19:41.190

    Reputation: 4 989

    0

    ASP VBScript, 43 bytes

    <%=createobject("scriptlet.typelib").guid%>
    

    Outputs a unique ID like {52076580-3151-4EE7-AAFD-D975CD141EE4} based on current date/time.

    Mario

    Posted 2016-11-30T20:19:41.190

    Reputation: 3 043

    0

    HSPAL, 18 bytes

    26FFFF
    400000
    120000
    

    Prints a random 16-bit integer.

    SuperJedi224

    Posted 2016-11-30T20:19:41.190

    Reputation: 11 342

    0

    Math++, 5 bytes

    $rand
    

    Produces a random 64-bit float

    SuperJedi224

    Posted 2016-11-30T20:19:41.190

    Reputation: 11 342

    0

    C, 22 bytes

    f(){putchar(time(0));}
    

    RosLuP

    Posted 2016-11-30T20:19:41.190

    Reputation: 3 036

    OP indicates in the comments that a full program is not needed and a function will suffice. Might I suggest replacing main with f to save 3 bytes? – Albert Renshaw – 2017-04-11T19:48:18.650

    yes i replace main with f... thank you and a good day – RosLuP – 2017-04-12T05:18:36.670

    0

    Chip-8, 4 bytes

    0xCFFF 'RND vF,FF
    0xFF18 'LD ST,vF
    

    This plays a sound for between 0 and 4.25 seconds. The seed always starts at 0, but it updates during the display interrupt which has a tiny chance of happening before the randomizer call, I hope.

    12Me21

    Posted 2016-11-30T20:19:41.190

    Reputation: 6 110

    0

    Pyt, 1 byte

    ɽ
    

    Returns a random 32-bit integer.

    Also 1 byte: ɹ, .

    mudkip201

    Posted 2016-11-30T20:19:41.190

    Reputation: 833

    Languages newer than the challenge should be marked "non-competing" – mbomb007 – 2018-02-11T20:32:11.050

    1

    – mudkip201 – 2018-02-11T21:03:36.790

    0

    Gol><>, 3 bytes

    x1h
    

    The 'x' is a randomizer for the direction of the pointer, the 1 pushes a 1, and the h outputs and halts.

    Try it online!

    KrystosTheOverlord

    Posted 2016-11-30T20:19:41.190

    Reputation: 681

    You can also do Sxh to print a random float between 0 and 1 – Jo King – 2019-03-01T02:31:34.327

    @JoKing I didn't think of that, thanks for pointing that out. that works as well. Though I don't think there is a smaller version of this – KrystosTheOverlord – 2019-03-01T02:57:30.220