coming soon

I'm working on a script randomly grab mp3s from a playlist and fill a CD with shuffled songs.

I'll be using bash's built-in random number generator which I believe is available in all versions.

Here's the shuffle function for those interested:

# Usage: shuffle <filename>
function shuffle () {

   cat "${@}"|grep -v "^#" | \
   while read mp3 ; do
      echo "$RANDOM $mp3"
   done | sort | cut -d" " -f2-

Requirements will be mpg321 and cdrecord.

2 thoughts on “coming soon

  1. Great idea for the shuffle! The “sort” might or should be “sort -n”, at least for consistency. BTW, I compared your shuffle() with a simple perl script using mainly “splice(@array, rand @array, 1)”. The perl shuffles 40k lines in 0.5 seconds whereas your shuffle() takes 8.2 seconds on a 2.4 GHz Xeon. Of course, the difference is of less importance when the number of lines is lower.

  2. This is a pimp trick.

    Here is another way to use the same. If you have a list of files you want to shuffle:

    ( find . -name ‘*.mp3′ | while read file ; do echo $RANDOM $file ; done ) | sort | cut -d’ ‘ -f2-

    The real trick to your code is your usage of “read”.
    Normally, I would use: for file in $(find … ) ; do echo $file ; done

    The problem is that files with spaces (from $IFS) will “break”. Using read, you seamlessly split the list by newline. Nice call. Word up.

    Rock on

Leave a Reply to Kevin Cancel reply

Your email address will not be published. Required fields are marked *