16 lines
470 B
Scala
16 lines
470 B
Scala
package ninetyNineScalaProblems.lists
|
|
|
|
import scala.util.Random
|
|
import scala.annotation.tailrec
|
|
|
|
object Problem25:
|
|
def randomPermute(list: List[Any]): List[Any] =
|
|
@tailrec
|
|
def loop(cursor: List[Any], acc: List[Any]): List[Any] =
|
|
cursor match
|
|
case head :: tail =>
|
|
loop(tail, cursor(Random.between(0, cursor.length)) :: acc)
|
|
case Nil =>
|
|
acc
|
|
|
|
loop(list, List()) |