TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Dimsum is like head or tail, but pulls randomly from the entire file or stream

29 点作者 snoble超过 12 年前

4 条评论

neilk超过 12 年前
This doesn't come with an elaborate test suite, but it does pretty much everything that does in a few dozen lines of Perl.<p><a href="https://github.com/neilk/misc/blob/master/randline" rel="nofollow">https://github.com/neilk/misc/blob/master/randline</a><p>I've had this script (or versions of it) around for more than a decade. I didn't know the technique had a name.
评论 #4834359 未加载
评论 #4835529 未加载
andrewcooke超过 12 年前
uses reservoir sampling -<a href="http://en.wikipedia.org/wiki/Reservoir_sampling" rel="nofollow">http://en.wikipedia.org/wiki/Reservoir_sampling</a><p>(so it presumably consumes the entire stream before giving any results; any alternative i can think of would not be "really random" unless you knew the length of the stream in advance).
评论 #4833655 未加载
评论 #4833653 未加载
评论 #4833892 未加载
nullc超过 12 年前
uhhh. You mean like shuf -n NNNN ?
评论 #4833724 未加载
评论 #4833733 未加载
patrick_grant超过 12 年前
I <i>really</i> don't like how this behaves for populating the array initially, and how it behaves for small inputs...<p><pre><code> $ seq 15 | dimsum -n 10 14 12 3 4 5 6 7 8 9 10</code></pre>
评论 #4845002 未加载
评论 #4834217 未加载