Bash + coreutils,20个字节
打高尔夫球
seq 0 $ 1 | shuf | sed 1q
shuf-生成随机排列
Shuf将使用以下代码:生成排列:
permutation = randperm_new (randint_source, head_lines, n_lines);
最终在 randint_genmax
/* Consume random data from *S to generate a random number in the range
0 .. GENMAX. */
randint
randint_genmax (struct randint_source *s, randint genmax)
{
...
randread (source, buf, i);
/* Increase RANDMAX by appending random bytes to RANDNUM and
UCHAR_MAX to RANDMAX until RANDMAX is no less than
GENMAX. This may lose up to CHAR_BIT bits of information
if shift_right (RANDINT_MAX) < GENMAX, but it is not
worth the programming hassle of saving these bits since
GENMAX is rarely that large in practice. */
...
}
反过来,它将 从低级随机性源中读取一些字节的随机数据:
/* Consume random data from *S to generate a random buffer BUF of size
SIZE. */
void
randread (struct randread_source *s, void *buf, size_t size)
{
if (s->source)
readsource (s, buf, size);
else
readisaac (&s->buf.isaac, buf, size);
}
即在低级别,shuf
输入值和从随机性源读取的数据之间不存在直接依赖关系(除了计算所需的字节缓冲区容量)。
rng()
提供0
-100
,如果n = 75
和函数为rng()%75
,则0-25会更常见...)