how to implement it with python?
the probability of each card is this card / all cards.
how to implement it with python?
the probability of each card is this card / all cards.
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
I ve been looking for it for a long time, but I can t find it. 1. After the direct upload of web is completed, the server cannot know whether the file was uploaded successfully, who uploaded it, and the information of the file 2. Using web to dire...
the work java spring does is not caused by the language feature limitations of java. so python should need something similar, but why didn t it develop? ...
I would like to ask the bosses here, the graduate students of Beijing Forestry University, what are the opportunities after graduation? Is it easy to find a job? I hope the bosses will answer, thank you very much! ...
I usually use int for storage. The unit of data storage is divided into points. For example, for goods worth one yuan, it is 100 in the database. I think it s simple and straightforward, and there s no need to think about compatibility or anything. ...
can you only use the markdown language in README.md in github? I ve experimented with using the markdown language in other files, but it doesn t work. Ask for popular science ~ ...
android studio development tools how does the android camera display range consistent with the range specified by surfaceview? do not wait to display the video range beyond the range specified by surfaceview. Do not show that the video range is only di...
my understanding is that traditional java and php will create new threads to handle blocked tasks. for Node.js from this diagram, the blocked tasks in the event queue are still left to the threads in the thread pool to handle the blocking events. ...
how to quickly convert multiple csv files into xls files in batches ...
< H2 > Development < H2 > ...
...
can t remote (GitHub) need to be manually added again? ...
the content of Dockerfile is as follows: FROM centos ADD redis-2.8.16.tar.gz usr local rediscluster ADD redis.conf usr local rediscluster ADD redis2.conf usr local rediscluster ADD redis3.conf usr local rediscluster ADD sentinel.conf usr local red...
I have found many articles on utf8_unicode_ci, utf8_general_ci and utf8_bin collation on the Internet, and I generally know that ci is case ignore, etc., but I didn t mention what other collations mean . what does the utf8mb4_polish_ci collation her...
I am doing the Titanic test and found that the meaning of such a code is not quite clear 1 Why is there a number in the first one, please tell me what does it mean 2 Why? + means to repeat what does it mean by using two 3 regular expressions? Thank y...
because the back end uses ajax to interact with the front end, it becomes necessary for the back end to write interface documentation. I used to use word to write interface documents, but recently I worked with colleagues to write the back-end, word is ...
< H2 > question < H2 > want to add a shopping cart table, let users add items to the shopping cart, click settlement to generate the order, but do not know how to design and associate < H2 > reference < H2 > the link I referenced https: blog....
can I run a command-line-based application on the Linux server through the browser and return the results to the browser? specifically, for example, there is an executable program on the server, and the input and output are images. Call it in shell as...
problem description In the project, the python3 code writes the hash structure data to the redis,java code to get it according to hash key, and the returned data is all null. for example, python stores the following data: The java code uses the ...
how to quickly copy a row in vscode? Is the operation of webstrom ctrl+D? ...
var createHandler = require( github-webhook-handler ) var handler = createHandler({ path: incoming , secret: myhashsecret }) this secret is the same as the secret set by GitHub backend. Why did you report an error ? Error: No X-Hub-Signature ...