Generating random numbers in Objective-C

前端 未结 13 2265
孤街浪徒
孤街浪徒 2020-11-22 02:07

I\'m a Java head mainly, and I want a way to generate a pseudo-random number between 0 and 74. In Java I would use the method:

Random.nextInt(74)


        
相关标签:
13条回答
  • 2020-11-22 02:45

    Generate random number between 0 to 99:

    int x = arc4random()%100;
    

    Generate random number between 500 and 1000:

    int x = (arc4random()%501) + 500;
    
    0 讨论(0)
提交回复
热议问题