Recently, I needed to perform a random sort of lines in vim. After a little bit of googling, I came up with the following:
(Works on Mac OS X Leopard and ubuntu 9.4)
Create the following perl script file:
#!/usr/bin/perl -w
use strict;
use List::Util 'shuffle';
my @lines = <>;
print shuffle( @lines );
Save the file and make it executable as well as easily accessible. Such as a directory that is in your PATH variable.
Now, fire up vim and visually select the lines you want to randomly select. Now, type:
!randsort.pl
There it is — randomly sorted lines.

Look up the Unix command shuf.
nice trick. it’s cleaner and easier to use if you make it a one-liner this way:
:%!perl -e 'use List::Util 'shuffle'; print shuffle();'then you can even put it in ur vimrc and bind it to a key if you want
e.g.
map r :%!perl -e 'use List::Util 'shuffle'; print shuffle();'then you can just tap ‘\r’ (unless you’re leader key is bound to something different) and vim will reshuffle your file.
windows users will need to install perl first tho
Awesome, thanks nik!