Timeline for Shortest code to produce non-deterministic output
Current License: CC BY-SA 3.0
20 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 6, 2017 at 20:15 | history | edited | totallyhuman | CC BY-SA 3.0 |
added 2 characters in body
|
Dec 5, 2016 at 18:27 | comment | added | Paŭlo Ebermann | Thanks. So it looks like this determinism was added with Java 8, or with the Linux version. | |
Dec 5, 2016 at 18:24 | comment | added | Poke | @PaŭloEbermann Eclipse with Java 7 | |
Dec 5, 2016 at 18:00 | comment | added | Paŭlo Ebermann | @Poke just for curiosity, could you compile this program on your Java 7 implementation and run it several times? Does it output different results? | |
Dec 5, 2016 at 0:38 | comment | added | Poke | @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 | |
Dec 4, 2016 at 19:23 | comment | added | Paŭlo Ebermann |
I 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?
|
|
Dec 2, 2016 at 18:36 | comment | added | Poke | @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. | |
Dec 2, 2016 at 17:47 | comment | added | pts |
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.
|
|
Dec 1, 2016 at 18:07 | comment | added | Poke | @OlivierGrégoire Yeah yeah but I'm still stuck in my ways :P | |
Dec 1, 2016 at 16:58 | comment | added | Olivier Grégoire |
In Java 8: ()->hashCode() for 14 bytes. Just sayin' ;)
|
|
Dec 1, 2016 at 4:59 | comment | added | Poke | @ais523 I think this meta post and comment should be relevant. | |
Dec 1, 2016 at 2:38 | comment | added | user62131 |
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…
|
|
Dec 1, 2016 at 1:31 | comment | added | Poke | @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. | |
Dec 1, 2016 at 1:08 | comment | added | user62131 |
Is 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.
|
|
Nov 30, 2016 at 22:32 | comment | added | Magic Octopus Urn | @Poke HA! I wondered what I over-looked there. Good catch. | |
Nov 30, 2016 at 22:17 | comment | added | Poke |
@carusocomputing I had toString in a previous version but then the return type is String which is longer than int . Save the bytes! :]
|
|
Nov 30, 2016 at 21:44 | comment | added | Magic Octopus Urn |
toString() also works, right? Outputs a random memory address if not overridden.
|
|
Nov 30, 2016 at 21:35 | comment | added | F. George | Because Java. Probably the best explanation of Java ever. | |
Nov 30, 2016 at 20:45 | history | edited | Poke | CC BY-SA 3.0 |
added 7 characters in body
|
Nov 30, 2016 at 20:36 | history | answered | Poke | CC BY-SA 3.0 |