Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caferrari/shuffle
Shuffle a huge amount of numbers
https://github.com/caferrari/shuffle
Last synced: about 2 months ago
JSON representation
Shuffle a huge amount of numbers
- Host: GitHub
- URL: https://github.com/caferrari/shuffle
- Owner: caferrari
- Created: 2014-01-24T18:02:25.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-26T21:54:12.000Z (about 11 years ago)
- Last Synced: 2024-10-28T05:39:07.585Z (3 months ago)
- Language: PHP
- Size: 133 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Caf\Shuffle [![Build Status](https://travis-ci.org/caferrari/Shuffle.png?branch=master)](https://travis-ci.org/caferrari/Shuffle)
===========This lib was made with the objective to shuffle a huge amount of numbers
Performance
-----------It's a lot slower than the combo range + shuffle functions but it does have a nice memory advantage:
10000000 (10 million) numbers:
range + shuffe: 1425.28 MB in 9 seconds
Caf\Shuffle: 38.59 MB in 24 seconds // Exported file: 40MB100000000 (100 million) numbers:
range + shuffe: PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 32 bytes)
Caf\Shuffle: 381.79Mb in 228 seconds // Exported file: 400MBAdvantages
----------You can export the generated numbers in a nice binary file to be used later or in another place so it becomes more useful
$r = new Caf\Shuffle\Shuffle(10000000);
$r->initialize();
$r->shuffle();
$r->exportToFile('rand.bin');It's very easy to reuse later:
$r = new Caf\Shuffle\Shuffle(10000000);
$r->loadFile('rand.bin');foreach ($r->getIterator() as $number) {
echo $number . PHP_EOL
}