[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...

---CUT-HERE---
#!/usr/bin/perl
# Program to output lines of file in random order

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

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

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





Reply to: