Giter Club home page Giter Club logo

fisher_yates_shuffle's Introduction

An Implementation of the Fisher-Yates Shuffle

Stratus3D

Note: The Fisher-Yates shuffle is very inefficient in Erlang due to the lack of an "Array" type. I created a function (fisher\_yates\_shuffle:improved\_shuffle/1) that provides a more efficient way of shuffling lists. Do not use fisher\_yates\_shuffle:shuffle/1 for anything other than experimentation.

Description

A simple implementation of the Fisher-Yates shuffle in Erlang. More information on the Fisher-Yates shuffle is available here: (http://bost.ocks.org/mike/shuffle/). There is also a implementation of the shuffle in JavaScript in the js/ directory.

Usage

Simply run make to compile the source code. To try out the code on the command line run erl -pa ebin/. The Fisher-Yates algorithm is in the shuffle/1 function:

1> fisher_yates_shuffle:shuffle([1,2,3,4,5,6,7,8,10,a,b,c,d,e,f]).
[c,8,b,3,2,6,10,4,d,5,e,f,a,1,7]

The more efficient algorithm is in the improved_shuffle/1 function:

2> fisher_yates_shuffle:improved_shuffle([1,2,3,4,5,6,7,8,10,a,b,c,d,e,f]).
[1,c,b,f,e,3,5,4,6,8,d,7,2,10,a]

Known Issues

No known issues. If you see something that could be improved feel free to open an issue on GitHub (https://github.com/Stratus3D/fisher_yates_shuffle/issues)

Contributing

Feel free to create an issue or pull request if you see something that could be improved.

fisher_yates_shuffle's People

Contributors

stratus3d avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.