Random float number

后端 未结 5 506
有刺的猬
有刺的猬 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:01

    Do you call it more than once? rand() will always return the same pseudo random. You might want to call srand() with some nice seed, like the current time.

提交回复
热议问题