Jump to content
  • Advertisement
Sign in to follow this  
AcidZombie24

Random Number Generator For Playlist

This topic is 3644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I notice winamp likes to play certain songs more then others. I figured if i kept a playlist history and mark how often a song was played i can even it out. But i also wondered if using a better RNG would work? it wouldnt, BUT instead of avoiding certain numbers maybe i can have a better RNG so the playlist choice is 'better'? I was thinking it would be cool if i could save the current RNG state and load it up next time my app starts. Is that possible? i dont want to regenerate with the seed key and loop up to where it currently should be. Is there a RNG lib like that? and if there isnt, is there any RNG that is more random then the standard rand()?

Share this post


Link to post
Share on other sites
Advertisement
If you want rand() to be actually random, you need to initialize it's starting point.

Slap this in the beginning of your main: srand ((int)time(NULL));

This will start rand()'s random number generation from the computer's time.

Share this post


Link to post
Share on other sites
Use Loot Generator for RNG.

It really is something like it. Each song has an count, the more it's played, the more likely it's to be selected. Just make sure you don't increment count when player uses its own algorithm, only when user selects a song.

Share this post


Link to post
Share on other sites
What is Loot Generator? All i could find is loot dropped/created by RNG and not an algorithm.

Infinity64: I knew how to make it random, its just that it isnt a great RNG :(. Maybe i should write a test to see what numbers it likes to come up with.

Antheus: thats a good idea.
Can anyone here point me to a RNG lib? I think i will not need the ability to save the rng state but if one exist...

Share this post


Link to post
Share on other sites
People always mistake 'even distribution' for random, when in true randomness, you get clustering. So some songs are bound to get played more then others.

From your post, I get that you want all songs to be played an equal amount of times? Or do you want your favorite songs to come up more (because you said better).

I use WMP for that, and I get to assign each MP3 a 1-5 star rating that gets embedded into the file. Not sure what WinAmp does, because I dropped it when it because a cumbersome eyesore that wouldn't save settings anymore.

Fill an array that is as large as your playlist, and in that array, store an int to how many times the song has been played. Then you can either sort this array randomly and play it in order, or choose a random entry and check to make sure it hasn't been played more then the rest of the songs (can't play it twice, until all other songs have been played once).

If you want to hear your favorite songs more often, then you store the rating in your array too. If it's less than a certain threshold, than you add in a 50/50 chance that it will get marked as played, but skipped over. Maybe a 1 star song gets skipped 75% of the time, and a 2 star 50%, 3 star song 25% of the time, 4 star 10% and 5 star always plays.

Share this post


Link to post
Share on other sites
If your after reasonable randomness, then seed the generator with the systems tick count.

If you want 'as unpredictable as can be' randomness then use something like the Mersenne Twister algorithm. This is simply taking 2 pseudo-random numbers and computing the highest common denominator. A good way of doing this is to get the system tick count, seed and get a number, then suspend the thread and do the same. Suspending the thread guarantees that the tick count will be at least greater than that of the previous count plus the time quanta of the next active thread. Computing the highest denominator of these 2 values gives a much more random number, as it is based not only on the system uptime, but also the number of threads you have running, as this effects the second seeding.

To get a 'random but even' (tm) generator for your songs, generate a random number as above between 1 and the total number of available songs. Keep a list of all your songs that have not been played for the current count. The play the song coresponding to the random number, remove it from the list and add it to another list. repeat the process reducing the number range by 1 each time. Eventually you will only have 1 song left to play. Once it's played switch the tables over and start again.

Share this post


Link to post
Share on other sites
Quote:
Original post by Daaark
People always mistake 'even distribution' for random, when in true randomness, you get clustering. So some songs are bound to get played more then others.

From your post, I get that you want all songs to be played an equal amount of times? Or do you want your favorite songs to come up more (because you said better).


I actually meant true randomness and not an event amount.
I have < 1000 songs in my playlist, i played more then 5000 songs, this is spanning several months and 90% of the time i have music playing. Never once has it played 'scar tissue' by RHCP. It could be a coincidences that it didnt play that song but it played many songs > 15 times. at least 10 of them. and it doesnt seem to be very random, which is why i wanted a better algorithm.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!