pipr.tools

shuffle-lines

Randomize line order

Aa Text

Try it

stdin0 chars
stdout0 chars

Example

Randomize the order of lines

Usage
$ echo "first
second
third
fourth
fifth" | shuffle-lines
View source
(input) => {
      const lines = input.split("\n");
      for (let i = lines.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [lines[i], lines[j]] = [lines[j], lines[i]];
      }
      return lines.join("\n");
    }

Suggested Pipelines

Related Tools