random number generation between two floats

后端 未结 2 1363
逝去的感伤
逝去的感伤 2021-02-09 14:23

I am trying to generate a random number between two floats (the max is increased by its half)

this is what I have so far but it\'s not working

    //ra         


        
2条回答
  •  [愿得一人]
    2021-02-09 15:19

    Include:

    #define ARC4RANDOM_MAX 0x100000000
    

    And then try this:

    double val = ((double)arc4random() / ARC4RANDOM_MAX) 
       * (maxRange - minRange)
       + minRange;
    

提交回复
热议问题