I need some help with an app. I need to make a random number generator for integers between zero and fifteen, which will then, depending on which number is created, push to a view with the corresponding number.
This is how I want it to work
Push a button –> random number generator gives a number between 0 and 15 –> view pushes to another view that has been assigned the number that the random number generator gave.
Can anybody help me with the code?
Thanks
arc4random()is the standard Objective-C random number generator function. It’ll give you a number between zero and… well, more than fifteen! You can generate a number between 0 and 15 (so, 0, 1, 2, … 15) with the following code:Then you can do a switch or a series of
if/elsestatements to push a different view controller:Or rather, upon rereading the question, it would look like the following:
And you’d have an
NSIntegerproperty on the MyViewController subclass.