scala - How to ensure that same random element is not selected twice -


i'm using below code randomly select 2 elements :

scala.util.random.shuffle(mylist).take(2) 

how can ensure 2 elements not selected twice ?

could remove random element list, create new list , use same code above ?

a bit more context nice; in, why not converting list easier handle task, iterator or array?

keeping list, see 2 options:

  1. use length of list pick 2 random numbers array of indices, check 2 random numbers aren't same , pull list.
  2. take 1, remove it, take instead of taking 2 @ once.

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -