News for hackers. Stuff that matters.
Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by koolba on Wednesday July 19, 2017 @02:06PM (#14806443)
A simpler way that's guaranteed to not repeat a song till the entire set has been played is: Assuming you have N songs, pick a prime P such that N is not divisible by P. Then pick a random index I (0 <= I < N) to start from. The index of the next song is I' = MOD(I + P, N). This method has the advantage of being O(1) regardless of the size of the playlist.

Another method is to pick a random key K and sort the entries of the playlist based on HMAC(SONG, K) (where SONG is the name or other identifier of the song). This has a number of interesting properties. For starters the playlist will be randomized (that's good). It will also keep it's overall order if a new song is added. The new song will get inserted based upon its HMAC. You can switch things up a bit by having K be a based on the current date. That way new songs will maintain their order and jumping to a track on a given day will continue the chain as before, but day to day you won't always hear the same tracks back to back.

Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by rcthompson on Wednesday July 19, 2017 @05:12PM (#14807982)
I think you're solving the wrong problem here. The goal is not to take a list and shuffle it once. That's trivial. The goal is: given a set of N songs, sample an arbitrarily long sequence of songs with replacement from this set such that the sequence "feels" random. Things that are random but don't "feel random" include: playing the same song too often, not playing a song often enough, and repeating the same sub-sequence of songs too often. The "shuffle the list once and repeat forever" approach fails hard on the last criterion. Generating a new shuffle every time through the list solves that issue but fails on the first two criteria, since a song could appear at the end of one shuffle and at the beginning of the next, resulting in repeating the same song twice in a row (or vice versa, resulting in the song not playing for 2N-2 songs).
Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by bryanlarsen on Wednesday July 19, 2017 @05:27PM (#14808121)
Also:

- don't play too many songs from the same artist in a row (and too many is probably 2) - don't play too many slow/fast/sad/angry/... songs in a row - ... instruments - ... genres - ... "feel" - ...

Deep AI is definitely needed to create playlists that "feel random". :)

Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by weaksauce on Wednesday July 19, 2017 @05:38PM (#14808205)
I don't think what people want is random when they say that... they want intelligently mixed playlists that meet a few criteria. no back to back songs from the same artist unless the pool of songs doesn't have sufficient variability in artists, not too frequent repeating of the same song, if you have a live version of the song it should be lowered sufficiently in probability of playing when another cover/live version played. basically people want to remove repetition.
Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by rcthompson on Thursday July 20, 2017 @01:05AM (#14810127)
I think in the general case you could imagine a NxN matrix of values between 0 and 1 representing similarity between N songs. Songs on the same album would have high similarity, especially consecutive tracks on the album, and different versions of the same song (e.g. live vs. studio) would also have high similarity. Then when selecting the next song, you would weight each available song's selection probability inversely to its similarity to the last few songs.
Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by oliv__ on Thursday July 20, 2017 @09:20PM (#14817438)
I don't see how this requires "deep AI". Aren't songs already categorized by their contents?
Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by gpvos on Wednesday July 19, 2017 @02:28PM (#14806637)
The prime method would mean that you would never hear some combinations of songs (for example, those who are an even number apart).
Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by Cogito on Wednesday July 19, 2017 @10:45PM (#14809702)
That's not true, at least for the even number apart example.

The prime method will sample songs p apart from each other, and it's easy to find examples of N and p where p is even, for example N=5 p=2. More generally, this method works for any n that is co-prime with N, so N=5 n=4 works as well.

There are lots of shufflings where subsequent songs are not separated by a constant amount, so your main point is true. There are many combinations of songs that you would never hear no matter which prime you picked.

To quantify just how many takes a little bit of work.

There are N! total shufflings possible. We know that there are N-1 or less numbers that are co-prime with N (you get N-1 when N is prime, less otherwise). For each number that is co-prime, we have N possible shufflings, each starting from a different point. This gives at most N(N-1) shufflings from the prime method (really the co-prime method).

As a percentage of total shufflings, we know the upper bound from the co-prime method is N(N-1) / N! == 1/(N-2)!. This very quickly goes to 0. For the first few N,

    N  % of shuffles
     2 100.00000%
     3 100.00000%
     4  50.00000%
     5  16.66667%
     6   4.16667%
     7   0.83333%
     8   0.13889%
     9   0.01984%
    10   0.00248%
    11   0.00028%
    12   0.00003%
    13   0.00000%
So for any reasonable number of songs, we know that _most_ shufflings will not be found by the prime shuffling method.
Re:Show HN: A Set of Dice That Follows the Gambler's Fallacy by Paul-ish on Wednesday July 19, 2017 @04:22PM (#14807563)
Wouldn't all random methods with some reasonable number of bits of randomness (eg 256) be unable to create all permutations of a sufficiently long playlist. The number of permutations of the playlist would be greater than the number possible random seeds. Eg a playlist with 60 songs has more than 2^270 permutations.