Because you have assigned the colour values to int
variables. Use float
(or CGFloat
) instead. Also (as @stackunderflow's said), the remainder must
be taken modulo 256 in order to cover the whole range 0.0 ... 1.0
:
CGFloat red = arc4random() % 256 / 255.0;
// Or (recommended):
CGFloat red = arc4random_uniform(256) / 255.0;