How to deal with the probability algorithm of drawing cards in the game, there is a limit on the number of each card, and the probability of drawing out will also change.

how to implement it with python?

the probability of each card is this card / all cards.

Mar.30,2021

can be regarded as a random number generation problem with a given probability distribution:

 

I don't understand your concerns.
there is no need to design at all.

the probability of each card is this card / all cards

is actually a random card taken from the stack and not put back.
if you use Python, you can directly use the random.choice () method to select a card from all the cards, and then remove the card from the stack. The card stack is empty.

if the stack of cards is very large and the composition list is not suitable, there is also a lot of room for optimization.

this kind of problem suggests converting the requirement into a mathematical problem first. In fact, there is no algorithm at all, as long as it is guaranteed to be random.

update:

must be designed, ah, this implementation will be extracted first with high probability, and then the scarcity probability will increase with the decrease of the total number of cards. It will result in a greater chance of getting scarcity later or later

this reply from the subject is not very rigorous, but I can understand it.
what I mentioned earlier is a true random algorithm (if I think the random selection is really random). In this case, there will be no such situation as described by the subject, "the higher the probability first, the greater the probability of extracting scarcity later." This is actually a simple question of probability theory, and there is no need to discuss it.
but the really random results may vary greatly under small samples. For example, if we play mobile games ten times in a row, the probability of the occurrence of a card is claimed to be 10%, and we may not even get it for several 10 times (90% ^ 10 = 34.8%, the probability of not getting out of ten times is 34%, the probability of not getting ten times twice is about 10%, and three times is 3%). One in 100 people will appear in 1% focus four times, which is still a high proportion), or five out of ten in a row.

so most of the time we choose to use pseudorandom. For example, the random in most games is pseudorandom.
pseudorandom means that the sample size is relatively small through artificial adjustment, and the overall result is still in line with mathematical expectations. For example, ten consecutive cigarettes must be rare.

one extreme is pure pseudorandom, the order in which the cards appear is set manually, and the next card is completely predictable. The other extreme is, of course, true random. Choose an appropriate degree in this interval for pseudorandom. The simplest method is to divide the sample evenly into N equal parts. For example, the whole is 100A, 10B, divided into 10 parts is each 10A1B, so at most 10 A will appear a B, at the same time to ensure that the rare B will not appear continuously. How many parts are divided into is the so-called degree.

there should be some articles, casually express their own views, and do not query any information, if there are fallacies, laugh at

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3e565-447ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3e565-447ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?