Comments (5)
话说为什么不用 Fisher–Yates shuffle 洗牌算法呢?
func Shuffle(slice []int) {
for i := len(slice) - 1; i >= 0; i-- {
j := rand.Intn(i + 1)
slice[i], slice[j] = slice[j], slice[i]
}
}
from blog_comment.
- 原作者大概觉得这个洗牌算法就已经均匀了
- fisher yates 在标准库内就有,不熟悉标准库呗
from blog_comment.
1. 原作者大概觉得这个洗牌算法就已经均匀了 2. fisher yates 在标准库内就有,不熟悉标准库呗
哦哦,理解了。
from blog_comment.
如果不洗牌,直接取呢?洗牌那不是增加是时间消耗吗
from blog_comment.
@chazyu1996 ,洗牌是应该考虑到如果取第一个节点失败了会继续取第二个,直接取的话,那失败了可能导致数组里后面那个节点的流量变大
update.2019.12.04
仔细想了想,理论上是可以不洗牌的,用互质数的性质来做依次遍历就可以完成伪随机的功能了
from blog_comment.
Related Issues (20)
- 是什么影响了我的接口延迟 HOT 2
- 为什么你不应该接受有 race 的代码 HOT 2
- Go 语言的 GC 实现分析 HOT 8
- 云原生如何使我们失业 HOT 3
- 调度流程(WIP) | Go 语言笔记 HOT 3
- [译]go 和 plan9 汇编 HOT 3
- go mod 之痛 HOT 4
- 为什么要旗帜鲜明地反对 orm 和 sql builder HOT 25
- memory ballast 和 gc tuner 成为历史 HOT 8
- go-redis 和 redis server 版本错位导致的高延时问题一例 HOT 2
- 为什么大公司讲的效率如此虚伪 HOT 11
- 自动调整 GOGC 优化 GO 的 GC CPU 占用 HOT 3
- aws 上 kafka 服务更新导致断连一例 HOT 4
- 平台到底有什么价值 HOT 9
- 如何在 kv 系统中支持简单的 SQL HOT 2
- 微服务税 HOT 6
- 谈一谈es的优势和限制 HOT 2
- sarama producer hang 又一例 HOT 2
- 下一次工业革命近在眼前了 HOT 13
- 非协作式抢占详解 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog_comment.