سؤال

I'm trying to generate random numbers from -50 to 50, but I don't know how to accomplish this task using arc4random.

Does anyone have any suggestions? Thank you!

هل كانت مفيدة؟

المحلول

You can get a random number up to 100 and substract 50. You will also need to cast it back to int, since arc4random its an unsigned type.

(arc4random() % (101)) - 50
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top