https://github.com/stratus3d/fisher_yates_shuffle
A simple implementation of the Fisher-Yates shuffle in Erlang
https://github.com/stratus3d/fisher_yates_shuffle
Last synced: about 1 year ago
JSON representation
A simple implementation of the Fisher-Yates shuffle in Erlang
- Host: GitHub
- URL: https://github.com/stratus3d/fisher_yates_shuffle
- Owner: Stratus3D
- License: mit
- Created: 2014-08-03T02:57:51.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-15T12:52:51.000Z (almost 12 years ago)
- Last Synced: 2025-02-08T21:13:40.030Z (over 1 year ago)
- Language: Erlang
- Size: 148 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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/](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](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.