random number generation between two floats

后端 未结 2 1364
逝去的感伤
逝去的感伤 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;
    
    0 讨论(0)
  • 2021-02-09 15:24

    Surely it's:

    float randomNumber = ((float)arc4random() / ARC4RANDOM_MAX * (maxRange - minRange)) + minRange;
    
    0 讨论(0)
提交回复
热议问题