func randomCGFloat() -> CGFloat {
return CGFloat(arc4random()) / CGFloat(UInt32.max)
}
extension UIColor
{
static func randomColor() -> UIColor {
let r = randomCGFloat()
let g = randomCGFloat()
let b = randomCGFloat()
return UIColor(red: r, green: g, blue: b, alpha: 1.0)
}
This is the code i am using in order to produce a random color. My question is the following. Can i get the r
,g
,b
parameters once i call the randomColor()
function twice? for example
`randomColor()` ->>> call
print the r,g,b
`randomColor()` ->>> call
print the r,g,b
Since it's a random number generator in order to produce a random color, i am afraid that every time i will try to access one of those variables inside the function i will get different results, since once it will be recalled(?). Help would be appreciated.If there is a different approach feel free to use it.