//Generate random verification code
1 //Nsmutablearray *marr = [[Nsmutablearray alloc]init]; //The following variables are used to enter the object in a variable immutable group, respectively2 3Nsarray *arrtest =[[Nsarray alloc]init];4 5 for(inti =0; I <Ten; i++)6 {7 //[Marr Addobject:[nsnumber numberwithint:i];8 9Arrtest =[Arrtest arraybyaddingobject:[nsnumber numberwithint:i];Ten } One A for(inti ='a'; I <='Z'; i++) - { - //[Marr addobject:[nsstring stringwithformat:@ "%c", I]]; the -Arrtest = [Arrtest arraybyaddingobject:[nsstring stringWithFormat:@"%c", I]]; - } - + for(inti ='A'; I <='Z'; i++) - { + //[Marr addobject:[nsstring stringwithformat:@ "%c", I]]; A atArrtest = [Arrtest arraybyaddingobject:[nsstring stringWithFormat:@"%c", I]]; - } - //NSLog (@ "%@", arrtest); - - - //The second step produces a random digital output in - toNsmutablestring *mstr =[[nsmutablestring alloc]init]; +NSString *str =[[NSString alloc]init];; - for(inti =0; I <4; i++) the { *str = [arrtest objectatindex:arc4random ()%Arrtest.count]; $ [Mstr Appendstring:str];Panax Notoginseng - the //str = [Marr objectatindex:arc4random ()% marr.count]; + A //MSTR = [Mstr stringbyappendingstring:str]; the + //[Mstr Appendstring:str]; - } $NSLog (@"%@", MSTR); $ - - [Arrtest release]; the //[Marr release]; - [MSTR release];Wuyi [str release]; the
------The first step , put all the numeric uppercase letters into an array ------
//[NSString stringWithFormat: Convert other types to objects
[Mutstr appendformat:<# (NSString *), ...#> infrequently used
variable array Increment object is AddObject: non-variable group splicing object is arraybyaddingobject:
//character types also need to be converted to Objects
//immutable type can be overwritten again
--------The second step to randomly remove an object from the array----------
//variable string:appendString No return value is to add a string to the original string
concatenation of two strings into an immutable string: Stringbyappendingstring is a return value
OC Array Application example-verification code