Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1004919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:12:33+00:00 2026-05-16T08:12:33+00:00

Is there a built-in method to do it? If not how can I do

  • 0

Is there a built-in method to do it? If not how can I do this without costing too much overhead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:12:33+00:00Added an answer on May 16, 2026 at 8:12 am

    Not built-in, but algorithm R(3.4.2) (Waterman’s "Reservoir Algorithm") from Knuth’s "The Art of Computer Programming" is good (in a very simplified version):

    import random
    
    def random_line(afile):
        line = next(afile)
        for num, aline in enumerate(afile, 2):
            if random.randrange(num):
                continue
            line = aline
        return line
    

    The num, ... in enumerate(..., 2) iterator produces the sequence 2, 3, 4… The randrange will therefore be 0 with a probability of 1.0/num — and that’s the probability with which we must replace the currently selected line (the special-case of sample size 1 of the referenced algorithm — see Knuth’s book for proof of correctness == and of course we’re also in the case of a small-enough "reservoir" to fit in memory ;-))… and exactly the probability with which we do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Without using any plugins, are there any built in function in jQuery or jQuery
CachingCallHandler of the enterprise library caches items using NoAbsoluteExpiration. But, I don't see a
I am trying to learn how to use Abaqus Scripting. I just downloaded Eclipse
We began a project using WebForms, and developed a somewhat complex portal system to
I am becoming a frequent user of eclipse, and I like it. However I
I have few DB tables, witch are build using inheritance from one table witch
The problem: I am embedding a CSS file into a custom control library with
I'm running through the problems on Project Euler to teach myself Ruby programming. I
I hope I asked that correctly. I am trying to figure out what element.sourceline

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.