# How to randomly select more then one items from a list?

Attention Topic was automatically imported from the old Question2Answer platform.

Assume I have the following list of 52 cards:

``````    Cards = ['club1' , 'club2',  'club3',  'club4', 'club5', 'club6','club7','club8','club9','club10' ,club11,'club12','club13','heart1', 'heart2', 'heart3',  'heart4', 'heart5', 'heart6', 'heart7',
``````

I want to select 13 items randomly from list at once,
What is the simplest way to retrieve items at random from this list?

A simple way is to shuffle the cards, and pick the first 13.

``````cards.shuffle()
var picked_cards = cards.slice(0, 13)
``````

If you want to keep the order in which cards were before, you can copy the array beforehand and truncate the copy to 13:

``````var picked_cards = cards.duplicate()
picked_cards.shuffle()
picked_cards.resize(13)
``````

Another way is to randomly pick 13 cards, while also checking we haven’t picked twice the same one, but it may be better suited for very large arrays (not like a card game):

``````var picked_cards = []
while len(picked_cards) < 13:
var card = cards[randi() % len(cards)]
if not picked_cards.has(card):
picked_cards.append(card)
``````

And a variant which removes cards as they are picked:

``````var picked_cards = []
while len(picked_cards) < how_many:
var picked_index = randi() % len(cards)
var card = cards[picked_index]
cards.remove(picked_index)
``````

@zylann thanks it worked well, but i am unable to get list of remaing cards,
i tried:

``````var rameincards = list(set(cards)-set(picked_cards))
``````

how to substract list from list for remaing cards.