Created
May 18, 2017 02:36
-
-
Save wilon/9ea0993d4cac1ae060d58a58e52ff426 to your computer and use it in GitHub Desktop.
Files were randomly assigned into n small files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fileName = __DIR__ . '/file.txt'; | |
$fp = fopen($fileName, 'r'); | |
while(!feof($fp)) { | |
$buffer = fgets($fp, 4096); | |
$k = mt_rand(0, 9); | |
$res[$k][] = $buffer; | |
} | |
fclose($fp); | |
foreach ($res as $k => $v) { | |
shuffle($v); | |
$fileStr = implode("", $v); | |
file_put_contents(__DIR__ . "/file_$k.txt", $fileStr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment