Random float number

后端 未结 5 515
有刺的猬
有刺的猬 2020-12-16 00:41

I wrote this function to get a pseudo random float between 0 .. 1 inclusive:

float randomFloat()
{
      float r = (float)rand()/(float)RAND_MAX;
      retur         


        
5条回答
  •  孤街浪徒
    2020-12-16 01:18

    You need to call

    srand(time(NULL));
    

    before using rand for the first time. time is in .

    EDIT: As Jonathan Leffler points out, this is easily predicted, so don't try using it for cryprography.

提交回复
热议问题