Random float number

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

    You have to initialize a random seed with

    void srand ( unsigned int seed );
    

    You can take for example the system time.

提交回复
热议问题