#Need help with creating a random picker out of a list that doesn't do doubles
1 messages · Page 1 of 1 (latest)
Just check if it’s already chosen and if yes you do it again
how do i do that? I'm kinda new
Send me ur code, I’m gonna give you some pointer
Yeah can you send the code ?
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
One question, is possiblePokerCards a list of unique items ? And is the order required ? If not, you could use a set it would be more efficient.
a python set. set()
@bot.event
async def on_message(message):
if bot.user.mentioned_in(message):
cards = random.sample(possible_poker_cards, 8)
for card in cards:
await message.channel.send(card)
Try this
and use set btw
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
Here you'd have to copy cards
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
Well, it works now
.tag close
Done with your help thread?
Please close your own help thread by using </close:1009144375709814897> with @teal birch.
Which way did you use, out of curiosity
honestly never heard of it lol
I used it like two times in prod code it's not very known
With this one xD
I can kinda understand that
the other one i can't
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
Anyway, thank you again