Generating a random bit - lack of randomness in C rand()

后端 未结 4 1699
礼貌的吻别
礼貌的吻别 2020-11-30 14:13

I am using rand() to generate either 0 or 1 (rand() % 2). I am seeding it using the current time (srand(time(NULL))).

After mu

4条回答
  •  再見小時候
    2020-11-30 14:25

    rand() is well-known to suck. random() is a bit better (sometimes), but drand48() and its family are much better.

    In you need better than that, look into the mersene twister or other PRNG libraries. Or check out /dev/random if that can provide enough data for your needs.

提交回复
热议问题