Suppose I need to generate random string to represent an RGB color. The string consists of #
and 6 hex digits: e.g. #ff0000
or#cafe00
.
I am doing it with random data generator like that:
import com.danielasfregola.randomdatagenerator.RandomDataGenerator._
import org.scalacheck.{Arbitrary, Gen}
def randomRGB(): String = {
implicit val arbitraryString: Arbitrary[String] = Arbitrary {
for {
r <- Gen.choose(0, 255)
g <- Gen.choose(0, 255)
b <- Gen.choose(0, 255)
} yield "#" + r.toHexString + g.toHexString + b.toHexString
}
random[String]
}
How would you improve it ?