-1

I am trying to create a Deck of cards type scenario, which I want to 'shuffle' and then pick a 'card'. The cards are in a list as 'S6' (6 of spades), 'CJ' (Jack of Clubs) and I want a card to be picked from index value 0 (top of the deck), and so would like to be able to move around each value in the list randomly.

Side question- Would picking a card by using a randomly generated index number produce a similar result? Coding Newboy here!

Matt Oram
  • 5
  • 4

2 Answers2

0

Yes. You can use random.shuffle() to mix up a list.

If you had a deck with the cards in order you could do something like

random.shuffle(deck)

FanMan
  • 160
  • 1
  • 15
0

As @dawg says, use random.shuffle:

import random
items = ['jack', 'king', 'queen', 'ace']
random.shuffle(items)

The function applies the change in-place, which means it alters the original object passed in and returns None.

See here https://stackoverflow.com/a/976921/9917694

N Chauhan
  • 3,407
  • 2
  • 7
  • 21