#Need help with creating a random picker out of a list that doesn't do doubles

1 messages · Page 1 of 1 (latest)

boreal depot
#

So basically i want to program a random.choice that avoids doing double outputs of the same. i am using 8 outputs in one message. Hopefully this is possible.

raw rain
boreal depot
#

how do i do that? I'm kinda new

raw rain
fast jasper
#

Yeah can you send the code ?

boreal depot
#
async def on_message(message):
       if bot.user.mentioned_in(message):
        pokerReply1 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply1)
        pokerReply2 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply2)
        pokerReply3 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply3)
        pokerReply4 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply4)
        pokerReply5 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply5)
        pokerReply6 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply6)
        pokerReply7 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply7)
        pokerReply8 = random.choice(possiblePokerCards)
        await message.channel.send(' ' + pokerReply8)

Its supposed to be picking poker cards out of the list

fast jasper
boreal depot
#

Its just a list of all the cards

#

and a set? Like what?

green tinsel
#

a python set. set()

fast jasper
#

and use set btw

green tinsel
#

you are all thinking way too complicated

#
cards = list_of_all_cards.copy()
for i in range(8):
   await message.channel.send(cards.pop(random.randrange(len(cards))) 
#

with cards being a copy of the canon list of cards

fast jasper
#

I'm not sure how that's easier but fair

#

random.sample seems like the canonical way of doing it to me

#

Admittedly I could have added a for loop in my example tho

green tinsel
#

ah i didnt see its only 8 cards and not the whole deck

#

well either way works

boreal depot
#

Well, it works now

fast jasper
#

.tag close

rustic martenBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @teal birch.

green tinsel
#

Which way did you use, out of curiosity

green tinsel
fast jasper
#

I used it like two times in prod code it's not very known

boreal depot
#

the other one i can't

green tinsel
#

pop removes an item from a list

#

making sure there can't be duplicates

#

and it just does that 8 times

#

but yea paillats way is kinda shorter since i forgot the copy lol

boreal depot
#

Anyway, thank you again