Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knuth-shuffle

Package Overview
Dependencies
Maintainers
7
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knuth-shuffle

The Fisher-Yates (aka Knuth) shuffle for Browser and Node.js

  • 1.0.8
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
12K
increased by14.25%
Maintainers
7
Weekly downloads
 
Created
Source

knuth-shuffle

The Fisher-Yates (aka Knuth) shuffle for Browser and Node.js

'nuf said.

The Fisher-Yates (Knuth) Shuffle

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.

Browser Example

<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);
}());

Node Example

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);
}());

Keywords

FAQs

Package last updated on 29 Oct 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc