Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
knuth-shuffle
Advanced tools
The Fisher-Yates (aka Knuth) shuffle for Browser and Node.js
'nuf said.
As Microsoft learned the hard way (see article below), function random() { return 0.5 - Math.random() }
turns out to be no-so-random at all.
The fisher-yates shuffle is an algorithm so simple that even IEEE floating point math can't screw it up!
I put this on npm as knuth-shuffle
because fisher-yates-shuffle
was just too long of a name and shuffle was already taken.
<script src="https://raw.github.com/coolaj86/knuth-shuffle/master/index.js"></script>
(function () {
'use strict';
var a = [2,11,37,42];
var b;
// The shuffle modifies the original array
// calling a.slice(0) creates a copy, which is assigned to b
b = window.knuthShuffle(a.slice(0));
console.log(b);
}());
Decentralized Install
npm install --save git+https://git.coolaj86.com/coolaj86/knuth-shuffle.js.git#v1.0
Centralized Install
npm install --save knuth-shuffle@1.0
(function () {
'use strict';
var shuffle = require('knuth-shuffle').knuthShuffle;
var a = [2,11,37,42];
var b;
// The shuffle modifies the original array
// calling a.slice(0) creates a copy, which is assigned to b
b = shuffle(a.slice(0));
console.log(b);
}());
FAQs
The Fisher-Yates (aka Knuth) shuffle for Browser and Node.js
The npm package knuth-shuffle receives a total of 13,715 weekly downloads. As such, knuth-shuffle popularity was classified as popular.
We found that knuth-shuffle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.