Awk rand function problems

Source: Internet
Author: User

Awk-V rand_str = $ random'
47 begin {m_num = argv [2]; s_num = argv [3]; srand (rand_str );
48 # select the first s_num for reservoir sampling
49 for (I = 1; I <= m_num; I ++) {A [I] = I };
50 for (I = s_num + 1; I <= m_num; I ++)
51 {---
52 m = int (RAND () * I) + 1;
53 If (M <s_num ){
54 TMP = A [m];
55 A [m] = A [I];
56 A [I] = TMP;
57}
58}
59 for (I = s_num + 1; I <= m_num; I ++) {delete a [I]} # Delete redundant
60 slen = asort (A, SA );
61 # For (I = 1; I <= s_num; I ++) {print SA [I]}
62 Index = 1;
63}
64 {
65 # each line
66 If (SA [Index] = nR) {index ++; print $0}
67} '$ mark_file $ mark_num $ sample_num> $ sample_file
68 hits =$ (awk '{if ($2 = 1) {print $2}' $ sample_file | WC-L );
69 Rm-RF $ sample_file
70 return $ hits

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.