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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -