Re: NSString, scramble
Re: NSString, scramble
- Subject: Re: NSString, scramble
- From: Fritz Anderson <email@hidden>
- Date: Sun, 1 Jul 2001 09:57:03 -0500
... and here, because I am obsessive, is the less-naive version of makeAnagram:
-- F
@interface NSString (Anagrams)
- (NSString *) makeAnagram;
@end
@implementation NSString (Anagrams)
- (NSString *) makeAnagram
{
unsigned length = [self length],
i;
unichar theChars[length];
// GCC, bless its heart, will dynamically size
// an auto array.
[self getCharacters: theChars];
for (i = 0; i < length; i++) {
unsigned index = randRange(0, length);
unichar temp = theChars[i];
theChars[i] = theChars[index];
theChars[index] = temp;
}
return [NSString stringWithCharacters: theChars length: length];
}
@end
--
Fritz Anderson <email@hidden>
Parallel Software, Inc <
http://www.parallel.com/>
Naperville, Illinois