How to ensure the same probability for samples of unknown total number

Source: Internet
Author: User

1. Randomly extract a number from an unknown large number

Solution: If this number is choice, replace it with the probability of 1/I for the number of I

Choice = 1

Replace choice = 2 with a probability of 1/2

Replace choice = 3 with a probability of 1/3

...

Until data traversal is complete

2. Extract K from an unknown large number

Solution: add the number of I to the sampling set with the probability of K/I. If the sampling set is full, replace one randomly.

If you want to extract 10

Then 1, 2, 3 ...... 10 is the initialization set

For 11, join the set with a probability of 10/11 and replace one randomly

For 12, join the set with a probability of 10/12 and replace one randomly

...

Until data traversal is complete

 

 

Http://archive.cnblogs.com/a/1949762/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.