INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

copying random files in sub-folders

copying random files in sub-folders

(OP)
hi there
i am trying to write a program in c++ that will allow me when it runs to select a number of mp3 files at random from a folder and its sub-folders then copy them to my mp3 player. the problem that i am having at the moment is doing the random picking of files, does anyone know how and help me in how i can achieve this?
Thanks  
mike

RE: copying random files in sub-folders

Hmm, doesn't look like this C++ category on Eng-Tips gets used all that much.  I just joined and expected to see a bit more activity...

I think what would be fine for your needs would be to use the standard C library function rand().  It returns a "random" integer; I use quotes around random because they are not truly random numbers.  However, it should provide adequate behavior for your application, which sounds like you'd like a "random" selection of songs.

Some folks will also tell you that rand() has crummy statistical properties.  That was true a decade or two ago for some C libraries, but most modern compilers have better libraries these days.  If you're worried about this, there are literally hundred of random number generators available on the web.  Knuth's "Art of Computer Programming" is a good starting area.  Numerical Recipes in C has a number of generators in it.  But for what you're doing, it's likely the built-in rand() function will do everything you need.

The usual technique is to divide rand() by double(RAND_MAX) and use the resulting number (which is >= 0 and < 1) to pick an integer from 0 to n-1, where n is the number of objects to choose from.

Finally, you probably want to select a sample from the set without replacement (i.e., hypergeometric sampling).  See Knuth for ways of doing this or let me know and I'll post a routine here.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close