Algs4-1.4.45 coupon collection problems

Source: Internet
Author: User

1.4.45 questions about coupon collection. Generate a random integer in the same way as the previous question. Experiment shows that the total number of random numbers required to generate all possible integer values is ~ N hn.
A: HN indicates a recursive relationship. The following experimental results show that HN is close to an equal difference sequence.

Public class e1d4d45
{
Public static void main (string [] ARGs)
{
For (INT I = 2; I <= 100000000; I = I + I)
{
Int [] DATA = new int [I];
Int COUNT = 0;
Int notrepeartcount = 0;
While (notrepeartcount <I)
{
Int r = stdrandom. Uniform (I );
Count ++;
If (data [R] = 0)
{
Notrepeartcount ++;
Data [R] = 1;
}
} // End while
Stdout. printf ("n = % 9d COUNT = % 9d count/N = % 3d \ n", I, Count, count/I );
} // End
} // End main
} // End class

Algs4-1.4.45 coupon collection problems

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.