Skip to content
RED SAGSkills
hard20 pts · first answer countsmathrandomalgorithms

Fisher-Yates with one wrong bound

This shuffle picks j with `Math.floor(Math.random() * i)` instead of `* (i + 1)`. What happens?

for (let i = a.length - 1; i > 0; i--) {
  const j = Math.floor(Math.random() * i)
  ;[a[i], a[j]] = [a[j], a[i]]
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions