1

I know I can get a random number for example from 0 to 700 using:

arc4random() % 362

But how can I get a random number in between for example 200 to 300?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253

2 Answers2

11

(arc4random() % 100) + 200

kovpas
  • 9,553
  • 6
  • 40
  • 44
1

Not to be picky, but I am pretty sure you have to add a number... if you want all the numbers from 200 to and including 300... use

200 + arc4random()%101; 

arc4random()%100 would give a random number from 0 to 99 so 300 would never occur...

wattostudios
  • 8,666
  • 13
  • 43
  • 57
tpun11
  • 21
  • 2