[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Program to randomize lines of text file

> Does anyone know of a script or binary that randomly output the lines
> of a text file, i.e its usage would be
> 	prog file -----> lines of file output in random order

I don't think this has anything to do with Debian, but it's only a few
seconds of programming, so...

# Program to output lines of file in random order

# Read File
while (<>) {
	push(foo, $_);

# Shuffle lines
for (0..$#foo) {
	$r = rand($#foo+1);
	($foo[$r], $foo[$_]) = ($foo[$_], $foo[$r]);

# Print it out
for (0..$#foo) {
	print $foo[$_];

Reply to: