Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
Last active December 30, 2016 17:09
Show Gist options
  • Save dannycabrera/e1478e745389e66e812b8fab19f068f5 to your computer and use it in GitHub Desktop.
Save dannycabrera/e1478e745389e66e812b8fab19f068f5 to your computer and use it in GitHub Desktop.
Random pastel color generator
using System;
using UIKit;
// based on http://blog.functionalfun.net/2008/07/random-pastel-colour-generator.html
public static UIColor RandomColor ()
{
Random random = new Random ();
// to create lighter colors:
// take a random integer between 0 & 128 (rather than between 0 and 255)
// and then add 127 to make the color lighter
int red = random.Next (128) + 127;
int green = random.Next (128) + 127;
int blue = random.Next (128) + 127;
// make color opaque
return UIColor.FromRGBA(red, green, blue, 255);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment