title: random color from an array for a different string
body: <p>I'd like to pick random number for a different string. The following example is similar to my scenario:</p>
  
  <pre><code>+ (UIColor *)ivl_randomColorWithSeedString:(NSString *)seedString {
  
      srand48(seedString ? seedString.hash : arc4random());
  
      float red = 0.0;
      while (red &lt; 0.1 || red &gt; 0.84) {
          red = drand48();
      }
  
      float green = 0.0;
      while (green &lt; 0.1 || green &gt; 0.84) {
          green = drand48();
      }
  
      float blue = 0.0;
      while (blue &lt; 0.1 || blue &gt; 0.84) {
          blue = drand48();
      }
  
      return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
  }
  </code></pre>
  
  <p>what I'd like to achieve is getting a random color for a different string, if I have the same string then return the same index.</p>
  
  <pre><code>- (void)setImageWithImage:(UIImage *)image orString:(NSString *)string colorArray:(NSArray *)colorArray circular:(BOOL)isCircular textAttributes:(NSDictionary *)textAttributes {
    if (!textAttributes) {
      textAttributes = @{
                         NSFontAttributeName: [self fontForFontName:nil],
                         NSForegroundColorAttributeName: [UIColor whiteColor]
                         };
    }
  
    NSMutableString *displayString = [NSMutableString stringWithString:@""];
  
    NSMutableArray *words = [[string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] mutableCopy];
  
    //
    // Get first letter of the first and last word
    //
    if ([words count]) {
      NSString *firstWord = [words firstObject];
      if ([firstWord length]) {
        // Get character range to handle emoji (emojis consist of 2 characters in sequence)
        NSRange firstLetterRange = [firstWord rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, 1)];
        [displayString appendString:[firstWord substringWithRange:firstLetterRange]];
      }
  
      if ([words count] &gt;= 2) {
        NSString *lastWord = [words lastObject];
  
        while ([lastWord length] == 0 &amp;&amp; [words count] &gt;= 2) {
          [words removeLastObject];
          lastWord = [words lastObject];
        }
  
        if ([words count] &gt; 1) {
          // Get character range to handle emoji (emojis consist of 2 characters in sequence)
          NSRange lastLetterRange = [lastWord rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, 1)];
          [displayString appendString:[lastWord substringWithRange:lastLetterRange]];
        }
      }
    }
  
    srand48(string ? string.hash : arc4random());
  
    NSUInteger randomIndex = arc4random() % [colorArray count];
    UIColor *backgroundColor = colorArray[randomIndex];
  
    if (image != nil) {
      self.image = image;
    } else {
      self.image = [self imageSnapshotFromText:[displayString uppercaseString] backgroundColor:backgroundColor circular:isCircular textAttributes:textAttributes];
    }
  }
  </code></pre>
  
  <p>What's the best approach on this?</p>