forked from wader/objcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjCheckGen.m
46 lines (32 loc) · 1.1 KB
/
ObjCheckGen.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#import "ObjCheckGen.h"
@implementation Gen
+ (NSNumber *) genNum {
return [NSNumber numberWithInt: arc4random()];
}
+ (NSNumber *) genBool {
return [NSNumber numberWithBool: arc4random() % 2 == 0 ];
}
+ (NSNumber *) genChar {
// return [NSNumber numberWithChar: (char) (arc4random() % 128)];
static NSString *const ascii = @" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
return @([ascii characterAtIndex:(arc4random()%[ascii length])]);
}
+ (NSArray *) genArray: (id(^)()) gen {
NSMutableArray* arr = [NSMutableArray array];
int len = arc4random() % 5;
int i;
for (i = 0; i < len; i++) {
[arr addObject: gen()];
}
return arr;
}
+ (NSString *) genString {
NSArray* arr = [self genArray: ^() { return (id) [Gen genChar]; }];
NSMutableString* s = [NSMutableString stringWithCapacity: [arr count]];
int i;
for (i = 0; i < [arr count]; i++) {
[s appendString: [NSString stringWithFormat: @"%c", [[arr objectAtIndex: i] charValue]]];
}
return s;
}
@end