There are lots of of challenges involving randomness. However, not all languages have a built-in method for randomness. Some languages, like python or most golfing languages make it really easy. You can simply call some built in function that will return a pseudo-randomly generated number. There is no boilerplate needed to seed the PRNG.
Other languages make it harder.
C/C++ has builtin PRNGs, but in order to get truly unpredictable results, you must call
srand(time(NULL));
, which seeds the PRNG with the current time. This is essentially an 18-byte penalty. As far as I know, Go works the same way.Turing tarpits and esolangs, such as brainfuck and Brain-Flak have the algorithmic capabilities to create a PRNG, but no way to get an unpredictable starting seed (such as OS utilities or time).
One potential solution is to allow the seed to come from user input. But this opens up a new can of worms. Imagine the hypothetical (underspecified) challenge:
Print the letter 'a' a random number of times.
If user input counts as a valid source of randomness in Brain-Flak, one could argue that I could simply do print('a'*input())
in python. Or even the equivalent in Brain-Flak:
{
({}<
((((((()()()){}){}){}){}){}())
>[()])
}{}
(For those who don't read Brain-Flak, this is basically the exact same thing as the python answer). Now, this hypothetical challenge is horribly underspecified, but the underlying problem is still there.
Now, it has been discussed before that time is a valid source of randomness for one value, not multiple. This post also addresses the meaning of the term "random". But neither of these address all of the potential problems with random answers. I'd like to get a definitive answer to all of these potential loopholes:
Is it valid for a challenge to use an unseeded PRNG? (This would affect answers such as this one)
Is user input a valid source of randomness? (This would affect this answer which was deemed invalid and deleted)
Is it valid to use user input to seed to a PRNG?
Should we treat all languages the same in this regard, or is it OK to use more forgiving rules for languages with less randomness capabilities?
NULL
is defined as0
. \$\endgroup\$NULL
, you're right that it means 0. That's the standard way to calltime
\$\endgroup\$print(1234)
andprint(random())
has the same observable behavior. Should we allow them? \$\endgroup\$srand(time(NULL));print(random())
is no more random either. It's simply maps each time to a different output. \$\endgroup\$