[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 78 KB, 688x1066, cards.png [View same] [iqdb] [saucenao] [google]
12719428 No.12719428 [Reply] [Original]

hello /sci/, i came from /g/ with a question in probabilities.
i needed to make a program to draw 2 random cards from a deck. i did it using the second method (right) while others did it following the first method. now i'm curious whether the 2 methods are equivalent and provide the same probabilities for all the different combinations of cards to be drawn.
so, are they?
implementations are in python

>> No.12719503
File: 314 KB, 3000x3000, 1606258736899.png [View same] [iqdb] [saucenao] [google]
12719503

Why don't you try them both and find out? Th;dt: yes, they're the same. Why would they be?

>> No.12721174

>>12719428
In the second procedure, The probability of drawing some ordered pair of cards (i,j) is (1/5)*(1/4). In the first procedure, once you draw the first card (it can be “i” with probability 1/5), the probability of only drawing “i” an infinite times is 0, so the probability of a different second card getting drawn at some point is 1. And so the probability of drawing a “j” at that point is 1/4. The product is the same.

>> No.12721225

>>12719503
>>12721174
got it. thanks a lot.

>> No.12721302
File: 742 KB, 2752x4342, 1613528670837.png [View same] [iqdb] [saucenao] [google]
12721302

>>12719428
bruh.

>> No.12721447

>>12719428
Also, the reason why you have two different graphs is because there is an ambiguity in the labels.
Implicitly, "draw a card" does not mean the same thing in the right graph and the left one. On the right it means "take an index at random, save the card value at that index and remove it from the deck. On the left the "remove it from the deck" part is implicitly removed, hence the need to make a correction after.
This is visible in the code : the part in each code that correspond to "draw a card" is not the same.

>> No.12721610

>>12719428
Anon, you need to do better than that.
>1) draw a random `c1` from 1 to n
>2) now `c1` is a hole. move card#1 to position `c1`
>3) draw a random `c2` from 2 to n.

You don't need to actually do (2). If `c2==c1`, c2=1.

>> No.12721675

>>12719428
probabilities aside, congrats OP, all your classmates are certified retards.

>> No.12722122
File: 203 KB, 480x521, file.png [View same] [iqdb] [saucenao] [google]
12722122

>>12721610
huh, that's pretty smart and efficient. you don't even need to shift the list or modify it at all
>>12721675
can't blame them, even textbooks do it this way

>> No.12723512

>>12721675
What's wrong with the left approach? It's the most optimized way I can think of.
>will only enter the loop 20% of the time, will only loop more than twice in a very small number of cases, chances of going through the loop more than 4-5 times is close to nonexistent
>when it doesn't enter the loop, it's the fastest way to pick two random cards with a cheap extra comparison on top
Yeah the indeterminate runtime is a bit of a problem, but most of the time it will be faster than anything that modifies the deck in memory.

>> No.12723766

>>12722122
Wait isn't it more logical to just use a set and stop when its length is 5?

>> No.12724339

>>12723512
now do 5 cards out of 52.

>> No.12724679

>>12724339
With larger decks, the difference between the solutions becomes greater. The odds of entering the loop and staying there get way lower, and the amount it takes to rearrange the deck in memory becomes far greater.

>> No.12724723

>>12723766
indeed, it would be. makes it faster too.

>> No.12724731

>>12724679
now you have 5 players. draw 25 cards from 52.

>> No.12724804

>>12724731
Sure, there's a tipping point where an implementation like the one on the right becomes better as more cards are drawn. I just don't see how choosing the left implementation for that specific problem, considering it is the fastest and most intuitive way to solve it, makes anybody a fucking retard. That is, unless you're one of those morons who tut-tuts at people who don't make a perfect, infinitely scalable solution to every single minor problem.

>> No.12725098

>>12719428
>implementations are in python
Do it in C++ faggot.

>> No.12725119
File: 139 KB, 612x792, LOWER CLASS.jpg [View same] [iqdb] [saucenao] [google]
12725119

>>12719428
>i
>/g/

>> No.12725234

>>12725119
>classy
>pictogram over prohibition sign
ew

>> No.12725268

>>12719428
>coding in python
>needing a flow chart
>can't into shit key
>reddit spacing
>can't into basic probability
>can't run basic frequency test
This is why cs majors aren't allowed here

>> No.12725272

>>12721174
P[j | j=/=i] = P[j and j=/=i]/P[j=/=i]= P[j]/P[j=/=i]= 1/5 / 4/5 = 1/4

>> No.12725735

>>12725268
CS majors aren't all like this retard, pls. Maybe he's a software engineer faggot who's sold his soul and wants to become a wage cuck programmer all his life.

>> No.12725757

>import random
>struggles to understand random

Thanks library