Random shuffling does not work for Range

Scala version 2.10.3 works on java 7

import scala.util.Random Random.shuffle(0 to 4) // works Random.shuffle(0 until 4) // doesn't work 

: 9: error: It is not possible to build a collection of type scala.collection.AbstractSeq [Int] with elements of type Int based on a collection of type scala.collection.AbstractSeq [Int].

The error message seems to really tell me, "You cannot do this." Does anyone know why?

+6
source share
1 answer

Scala prints invalid shuffle type parameters. You can force work with:

 Random.shuffle[Int, IndexedSeq](0 until 4) 

or broken with:

 Random.shuffle[Int, AbstractSeq](0 to 4) 

I do not know why this is due to incorrect parameters for Range , as until was returned, but correct for Range.Inclusive , as to was returned. Range.Inclusive directly subclasses Range without mixing in any way, so it can not be considered otherwise. It looks like a Scala bug for me.

+6
source

All Articles