For example, there is a Scala array val A = Array(\"please\", \"help\", \"me\"). How to choose a random element from this array?
val A = Array(\"please\", \"help\", \"me\")
A better answer that does not involve reshuffling the array at all would be this:
import scala.util.Random object sample { //gets random element from array def arr[T](items:Array[T]):T = { items(Random.nextInt(items.length)) } }
This also works generically