• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString, scramble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSString, scramble (From: "Michel M.J. Haver" <email@hidden>)

  • Prev by Date: Re: NSString, scramble
  • Next by Date: Re: AppKit source available as reference?
  • Previous by thread: Re: NSString, scramble
  • Next by thread: Re: NSString, scramble
  • Index(es):
    • Date
    • Thread