mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +00:00
shuf: Use the newly introduced AK::shuffle function
This commit is contained in:
parent
352048ce0e
commit
a559e26f68
1 changed files with 1 additions and 11 deletions
|
@ -54,17 +54,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (lines.is_empty())
|
||||
return 0;
|
||||
|
||||
// Fisher-Yates shuffle
|
||||
Bytes tmp;
|
||||
for (size_t i = lines.size() - 1; i >= 1; --i) {
|
||||
size_t j = get_random_uniform(i + 1);
|
||||
// Swap i and j
|
||||
if (i == j)
|
||||
continue;
|
||||
tmp = lines[j];
|
||||
lines[j] = lines[i];
|
||||
lines[i] = tmp;
|
||||
}
|
||||
AK::shuffle(lines);
|
||||
|
||||
Array<u8, 1> output_delimiter = { '\n' };
|
||||
for (size_t i = 0; i < min(head_count.value_or(lines.size()), lines.size()); ++i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue