-4
Is this Q too easy to ask, or has it just never been thought of?
Generate a random number, either 0 or 1 using a program
You may use a pre-defined function. The code must be executable. (It can't be just a function that requires more code to execute.) Randomness of the output will be verified by showing that it is not possible for a human/computer today to predict the output of the next execution (unless the exact algorithm is revealed), even when given an infinite set of outputs on previous executions of the code.
I'm looking for the most interesting code (never mind if it's lengthy).
Note: I had initially asked for the shortest code. The answer to that is 2 bytes long. It's O2
in Pyth, according to @Dennis
4All challenges require an objective winning criterion. Unless you specify how code length (code golf) and votes (popularity contest) are going to be combined, the challenge doesn't have one and is therefore off topic. – Dennis – 2015-11-01T15:09:03.363
1Also, this is trivial in most programming languages, but depends highly on what you mean by random in those where it's an interesting task. You should probably clarify how submissions are tested for randomness. – Lynn – 2015-11-01T15:11:37.903
@Dennis Is it okay now? I meant for the shortest code challenge to be only an additional one (since it's easier). – ghosts_in_the_code – 2015-11-01T15:24:11.753
11Asking for "interesting solutions" to trivial tasks doesn't usually inspire creativity. While popularity-contests are certainly on topic, you should expect quite a lot of downvotes, as they aren't usually very well received unless the challenge is actually best judged by humans (e.g. image processing). If you just went with a plain code golf, you might get boring answers in common languages with built-ins but very interesting answers in esoteric languages which have to implement their own random number generator. – Martin Ender – 2015-11-01T15:29:24.547
@MartinBüttner There can be interesting answers such as '#@>#0?1@' in Befunge. Are you going to reopen the Q? – ghosts_in_the_code – 2015-11-01T15:38:12.470
@ghosts_in_the_code I reopened it 8 minutes ago. My point is that you'll still get interesting answers exactly like the one you've mentioned if you make it a code golf. – Martin Ender – 2015-11-01T15:41:29.010
1For such a simple and standard task, popularity contest is meaningless. Many languages have an obvious way to do it. You might get answers that do it in a weird way, but most will just use the built-in made for it. For these, there's nothing to judge except the choice of language. There's no point making weird embellishments either for the sake of creativity. – xnor – 2015-11-01T17:59:17.503
The question as specified is impossible without custom hardware by a simple counting argument. – Peter Taylor – 2015-11-01T19:17:22.730
+(Bool.pick)
– Brad Gilbert b2gills – 2015-11-02T18:03:18.143for determining how random the function is, I would recommend simply running things many times and counting the results. Since I assume you want uniform randomness, you'd be looking for 50/50. – Liam – 2015-11-02T21:49:09.833