Leave a Comment:
11 comments

Hi, Nice tutorial, but it’s not “random”. Instead of incrementing y, you should just set it to a random number between 0 and n-1, where n is the number of messages in your case statement. You could also store your message strings in an array and use y to index into the array.
Reply
/RandomMessage/Classes/HappyRandomMessageViewController.m:156:0 /RandomMessage/Classes/RandomMessageViewController.m:156: warning: property ‘userText’ requires method ‘-userText’ to be defined – use @synthesize, @dynamic or provide a method implementation
This is how it looks
– (void)dealloc {
[super dealloc];
}
@end
Any inputs will be appreciated…
Reply
sorry, this is wrong it shows a continuous line of messages for random messages use this code
– (void)updateText {
int rNumber = rand() % 8;// divides by number of fields to give a perfectly random generation
switch (rNumber) {
case 0: [userText setText:@”Hi”]; break;
case 1: [userText setText:@”Hello”]; break;
case 2: [userText setText:@”Hello World”]; break;
case 3: [userText setText:@”iPhone”]; break;
case 4: [userText setText:@”iPad”]; break;
case 5: [userText setText:@”iPod”]; break;
case 6: [userText setText:@”Mac Mini”]; break;
case 7: [userText setText:@”Enter Your Name”]; break;
case 8: [userText setText:@”Enter Your Age”]; break;
default: @”Apple”;
break;
}
}
Reply
Hi Jack, your example has also the same results as the first one.
I have change it to:
– (void)updateText {
int rNumber = arc4random() % 8;
switch (rNumber) {
case 0: [textView setText:@”1″]; break;
case 1: [textView setText:@”2″]; break;
case 2: [textView setText:@”3 “]; break;
case 3: [textView setText:@”4″]; break;
case 4: [textView setText:@”5″]; break;
case 5: [textView setText:@”6”]; break;
case 6: [textView setText:@”7 “]; break;
case 7: [textView setText:@”8″]; break;
case 8: [textView setText:@” 9″]; break;
break;
}
}
and it works pretty good.
Reply

Great article… I need some help on step5…Could you send me email or contact information?
Reply
How would one dot his for randomly selected views as in switch the views randomly using a button pressed method? Any assistance would be greatly appreciated.
Thank,
Rob DeNicola
Reply
Why I get the same sequence of random number every time I run with ran()?
I’m using Xcode.
Reply
Hi, I do believe this is an excellent blog.
I stumbledupon it 😉 I may come back yet again since i have book-marked it.
Money and freedom is the greatest way too change, may you be rich and continue
to guiide others.

Hi
Thanks for your comment.
Please do come back and check us out from time to time. We’re starting a new series of blogs this month. We’ll be releasing four blog posts each month covering all aspects of iOS and iPhone development.
Reply