random number generation between two floats

后端 未结 2 1401
逝去的感伤
逝去的感伤 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:24

    Surely it's:

    float randomNumber = ((float)arc4random() / ARC4RANDOM_MAX * (maxRange - minRange)) + minRange;
    

提交回复
热议问题