| New Reply |
pick k (assume k < n) items from the list |
Share Thread |
| Nov26-10, 08:27 PM | #1 |
|
|
pick k (assume k < n) items from the list
I have a list of n items. My goal is to pick k (assume k < n) items from the list such that each one of them as probability 1/n of being chosen. Would it be possible to accomplish this without knowing n, in one reading?
thanks |
| Nov26-10, 10:47 PM | #2 |
|
|
Besides: Are you picking a subset from a set? Set from a list? List from a set? List from a list? I think there is a difference. |
| Nov26-10, 11:04 PM | #3 |
|
|
Let's say there is a file composed of n lines. I do not know the number of lines in advance. I wish to pick k random lines from the file, with one read only (without storing the lines in memory and then doing the rest)...
|
| Nov26-10, 11:19 PM | #4 |
|
|
pick k (assume k < n) items from the listDuring your one pass through, process the i-th line if i is an element in L, skip the rest. Obviously you will not be able to read k lines if the actual value of n > m. But this is the best I can think of. |
| Nov26-10, 11:35 PM | #5 |
|
Recognitions:
|
I assume you mean k/n, not 1/n.
|
| Nov26-10, 11:46 PM | #6 |
|
|
|
| Nov26-10, 11:48 PM | #7 |
|
Recognitions:
|
|
| Nov27-10, 12:05 AM | #8 |
|
|
However this k<n assumption is still pretty suspicious. How can one claim not to know n yet make the claim that k<n?
|
| Nov27-10, 12:59 AM | #9 |
|
Recognitions:
|
|
| Nov27-10, 02:45 AM | #10 |
|
|
|
| New Reply |
| Tags |
| permutation, random, shuffling |
Similar discussions for: pick k (assume k < n) items from the list
|
||||
| Thread | Forum | Replies | ||
| array shuffling in fortran | Programming & Comp Sci | 1 | ||
| More Staff Shuffling | Forum Feedback & Announcements | 36 | ||