Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-13-2011, 12:14 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 12
niteboater is on a distinguished road
Cool faux ssn generator

greetings !

need a fake social security number generator for a comedy app Im writing. A start button will startup the app showing a "scanning" process (totally fake) and one of the scanning attribs will be a series of displayed ssn's.
I need to have about 20-40 or so of these faux 123-45-6789 type numbers, displaying for about 1/2 sec each.
I would love to have hypens as well.

Later I will add in faux images to represent "fingerprints", "maps", "mug shots". All for fun, nothing real here, except my code.

Three buttons:

1. START

2. STOP

3. CANCEL - same as stop but makes a funny sound

herez my code - it doesnt build correctly...


int min = 101;
int max = 987;
int firstblock = (arc4random() % (max - min)) + min;
return [NSString stringWithFormat:@"%d", firstblock];

int min2 = 10;
int max2 = 98;
int secondblock = (arc4random() % (max2 - min2)) + min;
return [NSString stringWithFormat:@"%d", secondblock];

int min3 = 1005;
int max3 = 9986;
int thirdblock = (arc4random() % (max3 - min3)) + min;
return [NSString stringWithFormat:@"%d", thirdblock];



NSString *str = [NSString stringWithFormat:@"firstblock", @"secondblock", @"thirdblock"];

textview.text = [NSString* stringWithFormat];

Last edited by niteboater; 03-13-2011 at 12:23 PM.
niteboater is offline   Reply With Quote
Old 03-13-2011, 01:01 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 342
flamingliquid is on a distinguished road
Default

Change the last two lines to this:
Code:
NSString *str = [NSString stringWithFormat:@"%@-%@-%@", firstBlock, secondBlock, thirdBlock];

textview.text = str;
But you really should learn the language more.
__________________
17 year old nerd.
Send me a PM. Maybe I can help.
flamingliquid is offline   Reply With Quote
Old 03-13-2011, 01:55 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 12
niteboater is on a distinguished road
Default build succeeds / app crashes / now what ?

Hi FL,

thanks for the tip. The build does now succeed but the end result still fails, ie, iPhone simulator 3.2 crashes. Its amazing how difficult it was just to get this much done, Ive spent many hours perusing Dev Documentation, internet postings, and random stabs in the dark. Even highliting terms such as "NSSTring" and using the "lookup in documentation" is overwhelming. Dev docs strike me as mostly confirmatory for people who already know what they are looking for but need "spelling help".

By contrast, learning any other "language" such as Russian, Italian, Hungarian, one can simply go to RosettaStone.com and get polished, presentable, understandable material in step by step format.

Too bad they dont offer "XCode" !

Here's my modified code including your tip:

#import "random08ViewController.h"

@implementation random08ViewController

- (IBAction)random08

{
int min = 101;
int max = 987;
int firstBlock = (arc4random() % (max - min)) + min;

int min2 = 10;
int max2 = 98;
int secondBlock = (arc4random() % (max2 - min2)) + min;

int min3 = 1005;
int max3 = 9986;
int thirdBlock = (arc4random() % (max3 - min3)) + min;


NSString *str = [NSString stringWithFormat:@"%@-%@-%@", firstBlock, secondBlock, thirdBlock];

textview.text = str;


}
------------------------------------------------------------------------------
And the only other file in play is the viewcontroller.h file which has:

#import <UIKit/UIKit.h>

@interface random08ViewController : UIViewController {

IBOutlet UILabel *textview;
}

-(IBAction)random08;


@end
-----------------------------------------------------------------------------
niteboater is offline   Reply With Quote
Old 03-13-2011, 02:18 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 12
niteboater is on a distinguished road
Default figured it out, this works !

int min1 = 101;
int max1 = 987;
int firstBlock = (arc4random() % (max1 - min1)) + min1;

int min2 = 10;
int max2 = 98;
int secondBlock = (arc4random() % (max2 - min2)) + min2;

int min3 = 1005;
int max3 = 9986;
int thirdBlock = (arc4random() % (max3 - min3)) + min3;

NSString *str = [NSString stringWithFormat:@"%d-" @"%d-" @"%d", firstBlock, secondBlock, thirdBlock];

textview.text = str;
niteboater is offline   Reply With Quote
Old 03-13-2011, 05:41 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by niteboater View Post
int min1 = 101;
int max1 = 987;
int firstBlock = (arc4random() % (max1 - min1)) + min1;

int min2 = 10;
int max2 = 98;
int secondBlock = (arc4random() % (max2 - min2)) + min2;

int min3 = 1005;
int max3 = 9986;
int thirdBlock = (arc4random() % (max3 - min3)) + min3;

NSString *str = [NSString stringWithFormat:@"%d-" @"%d-" @"%d", firstBlock, secondBlock, thirdBlock];

textview.text = str;
Righto. You need to read up on format strings.

Take a look at this article:

<b><u><a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html%23//apple_ref/doc/uid/TP40004265-SW1
">String Format Specifiers</a></u></b>


The "%@" format takes an object as a parameter, and NSLog calls that object's -description method. Usually you use "%@" to pass in other strings.

If you pass in a simple type like an int or a float for a "%@", you will crash.

Do a search on "String Format Specifiers" in XCode and bookmark it. You will find yourself referring to that page of the docs over and over and over.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
fake, number generator, random, string

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 367
8 members and 359 guests
Absentia, akphyo, apatsufas, BinHex, fredidf, Kirkout, MarkC, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0