GithubHelp home page GithubHelp logo

Comments (5)

imhuster avatar imhuster commented on May 30, 2024

话说为什么不用 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.

cch123 avatar cch123 commented on May 30, 2024

@imhuster

  1. 原作者大概觉得这个洗牌算法就已经均匀了
  2. fisher yates 在标准库内就有,不熟悉标准库呗

from blog_comment.

imhuster avatar imhuster commented on May 30, 2024

@imhuster

1. 原作者大概觉得这个洗牌算法就已经均匀了

2. fisher yates 在标准库内就有,不熟悉标准库呗

哦哦,理解了。

from blog_comment.

z1son avatar z1son commented on May 30, 2024

如果不洗牌,直接取呢?洗牌那不是增加是时间消耗吗

from blog_comment.

cch123 avatar cch123 commented on May 30, 2024

@chazyu1996 ,洗牌是应该考虑到如果取第一个节点失败了会继续取第二个,直接取的话,那失败了可能导致数组里后面那个节点的流量变大

update.2019.12.04
仔细想了想,理论上是可以不洗牌的,用互质数的性质来做依次遍历就可以完成伪随机的功能了

from blog_comment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.