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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Shuffling

52 点作者 stansmith超过 10 年前

7 条评论

ryandrake超过 10 年前
While understanding the how&#x2F;why of algorithms is great, a word of advice: If this were a real project and your standard library has a shuffle() function, just use that one and get on with life.<p>Save yourself from having to worry about your hand-crafted one being subtly wrong. Save your peers from having to debug your hand-crafted one years after you&#x27;ve left the company. This tip goes for basically any routine that already comes built-into your language or libraries. Spend your time writing code that doesn&#x27;t already exist. I&#x27;m looking at you, co-worker from 5 or so years ago who felt he had to re-implement strings, linked lists, and sorting.
Kortaggio超过 10 年前
This is great, I never had intuitive understanding of why the naive shuffle was bad other than a vague notion of the fallibility of pseudo-random number generators. Seeing a math equation is one thing but seeing a tree of all possible outcomes visualized in front of you not only makes the bias blatant, but also makes it obvious <i>why</i> the bias is occurring.
评论 #8671806 未加载
mattxxx超过 10 年前
I love the idea of combining this with the idea of proving code.<p>Like, &quot;how can I prove my approach &#x27;shuffles&#x27; an array?&quot; ... I mean, just because it looks right... doesn&#x27;t mean it is.
评论 #8672967 未加载
karmadude超过 10 年前
Here is a demo of shuffling using a combination of Hindu &amp; Riffle shuffle <a href="http://karmadude.github.io/CardShuffler/" rel="nofollow">http:&#x2F;&#x2F;karmadude.github.io&#x2F;CardShuffler&#x2F;</a><p>I heard someone say once that we have to shuffle a deck of cards 7 times to get a good shuffle. This demo was setup to try to simulate how we shuffle cards, and turns out shuffling around 5 times gives a pretty good shuffle.
评论 #8672888 未加载
betaveros超过 10 年前
There was a Google Code Jam problem this year precisely about detecting the difference between the fair shuffle and the &quot;terribly, terribly wrong&quot; shuffle: <a href="https://code.google.com/codejam/contest/2984486/dashboard#s=p2" rel="nofollow">https:&#x2F;&#x2F;code.google.com&#x2F;codejam&#x2F;contest&#x2F;2984486&#x2F;dashboard#s=...</a>
chuckledog超过 10 年前
Coincidentally, shuffling was the subject of this week&#x27;s puzzle on &quot;Interview Cake&quot;: <a href="https://www.interviewcake.com/question/shuffle" rel="nofollow">https:&#x2F;&#x2F;www.interviewcake.com&#x2F;question&#x2F;shuffle</a>
glomph超过 10 年前
What motivated that choice of psudocode? I found it very hard to read.
评论 #8671986 未加载