Berkeley CSUA MOTD:Entry 49075
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2024/11/23 [General] UID:1000 Activity:popular
11/23   

2008/2/5-7 [Computer/SW/Database] UID:49075 Activity:nil
2/4     Think this has been asked before on motd but how does one select
        X elements out of a stream of N, where N is unknown?
        \_ Pick the first X elements.
        \_ Assuming your question really is "how do I pick x elements from a
           stream of n, where n is unknown and the chance of any element being
           picked is x/n:
           Pick the first x elements from the stream.
           For each element afterwards if a random number between 1 and
            currently seen elements is < x replace a random element in
            your picked list with the next element from the stream.
           Repeat until the stream is empty.
           This alg probably has an off by 1 error or two in it, but it
            is the basic idea.
           \_ Wow, this was an interview question where X is 1 (how to
              pick a random line from a text file reading the file
              only once). But I never throught about a generalized
              version. Thanks!
2024/11/23 [General] UID:1000 Activity:popular
11/23   

You may also be interested in these entries...
2013/4/9-5/18 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Apps, Computer/SW/Languages/Perl] UID:54650 Activity:nil
4/04    Is there a good way to diff 2 files that consist of columns of
        floating point numbers, such that it only tells me if there's a
        difference if the numbers on a given line differ by at least a given
        ratio?  Say, 1%?
        \_ Use Excel.
           1. Open foo.txt in Excel.  It should convert all numbers to cells in
	...
2010/1/22-30 [Computer/HW/Laptop, Computer/SW/OS/OsX] UID:53655 Activity:high
1/22    looking to buy a new development laptop
        needs ssdrive, >6 hr possible batt life, and runs linux reasonably
        Anyone have a recommendation? Thx.
        \_ thinkpad t23 w ssdrive and battery inplace of drive bay
        \_ Ever wondered what RICHARD STALLMAN uses for a laptop?  Well,
           wonder no more!
	...
2009/2/27-3/5 [Computer/Networking] UID:52658 Activity:nil
2/27    I need to buy a wireless router, can u guys help me out?   I need the
        following features:  wireless, G or better, PPTP dial up, PPoE dialup,
        VoIP/SIP register, DDNS, uPnP.
        I am having a such hard time to find a review site which allow me to
        select these features.   Any ideas?  There are a couple model from
        this small company Draytek has these features, I am having the hardest
	...
2008/9/22-29 [Computer/SW/Database] UID:51265 Activity:nil
9/22    In SQL, how can I do something like this:
        SELECT ip_addr, count(*) AS ct FROM table WHERE
          ct > 10 GROUP BY ip_addr?
        I can't get the conditionals to recognize 'ct'
        \_ SELECT ip_addr, count(*) AS ct FROM table HAVING
            count(*) > 10 GROUP BY ip_addr?
	...