# Bronze Challenge: My approach (complete randomization)

#1

I love randomization

A block for getting random numbers within a range from the previous number, in 1/100 steps:

```float (^randomChange)(int,int,float) = ^(int plusRange, int minusRange, float currentValue) { int cv = currentValue*100; plusRange += minusRange; int value = ((arc4random()%plusRange)-minusRange+cv)%101; if (value<0) { return (float)(101+value)/100; } return (float)value/100; };```

A method to change the given color by a random value, using the block above:

``````- (UIColor*)changeColor:(UIColor *)currentColor
{
//those numbers represent "plus range" and "minus range". They can be altered freely.
int i = 10;
int z = 10;

//initialize the floats for the "current color" method
float red = 0;
float green = 0;
float blue = 0;
float alpha = 0;

//split the colors
[currentColor getRed:&red green:&green blue:&blue alpha:&alpha];

//change the values
red = randomChange(i,z,red);

green = randomChange(i,z,green);

blue = randomChange(i,z,blue);

//put the color together again and return
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}``````

Of course, you have to set the currentColor to the circle color before the iteration in the “drawRect” method, then set the currentColor with the method above and itself as argument, in order to have a new color in the next iteration.

[code]

//set Color and thickness
CGContextSetLineWidth(ctx, 10);
UIColor *currentColor = [self circleColor];
[currentColor setStroke];

``````//draw a number of circles
CGContextStrokePath(ctx);
[b]currentColor = [self changeColor:currentColor];[/b]
[b][currentColor setStroke];[/b]
}
``````

…[/code]

The advantage is, that if you don´t want too “assorted” colors, you can limit the range and have a nice kind of gradient. You could even use the block directly for only one color, that it is more determined which color you will get.
UIColor blackColor, UIColor whiteColor and all shades in between will not work with this code, because it cannot be properly split into RGBA colors (some problem with the color space, i guess.)

#2