I noticed the following unexpected behavior when using ScalaCheck Gen.pic , which (for me) indicates that its collection is not quite random, even though its documentation says so:
I executed the following three small programs in order (within 2 days, at different times, as it may be important) after installation
implicit override val generatorDrivenConfig = PropertyCheckConfig(
maxSize = 1000,
minSize = 1000,
minSuccessful = 1000)
to get a decent sample size.
Program number 1
val set = Set(1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50)
val g = Gen.pick(3, set).map { _.toList }
forAll (g) { s => println(s) }
From 3,000 numbers generated in 2 different runs, I got a surprisingly similar and rather nonrandom distribution (the numbers are rounded, only 5 are listed), as for the entire listing here):
- Number : startup frequency # 1, startup frequency # 2
- 15 : 33%, 33%
- 47: 22%, 22%
- 4: 15%, 16%
- 19: 10%, 10%
- 30: 6%, 6%
( : , , )
2
val list: List[Int] = List.range(1, 50)
val g = Gen.pick(3, list)
forAll (g) { s => println(s) }
List
, , "" (3x1000 ):
- 49: 33%, 33%
- 48: 22%, 22%
- 47: 14%, 14%
- 46: 10%, 10%
- 45: 6%, 6%
, , 1.
. 10 +/- 1% , "".
3
, , Set
( 1) List
( 2):
val set: Set[Int] = List.range(1, 50).toSet
val g = Gen.pick(3, set).map { _.toList }
forAll (g) { s => println(s) }
, 2 (List
!), ( , 3 * 1000 2 ) :
- 49: 33%, 33%
- 48: 23%, 22%
- 47: 16%, 15%
- 46: 9%, 10%
- 45: 7%, 6%
, ( ), , Gen.pick
( - , , "" ), "", .
Gen.pick
, # 672 seed0
:
def pick[T](n: Int, l: Iterable[T]): Gen[Seq[T]] = {
if (n > l.size || n < 0) throw new IllegalArgumentException(s"invalid choice: $n")
else if (n == 0) Gen.const(Nil)
else gen { (p, seed0) =>
// ...
( Gen.scala scala.util.Random), , - .
Gen.pick
? , "" ?