Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Let Rating(i) be the user rating of the ith song, bounded by 0 < Rating(i) < RMAX
- Let TMAX be the maximum amount of tickets a song can have
- Let Lists be a matrix of size TMAX x RMAX
- Initialization:
- For (i=0 to TMAX-1)
- For (j=0 to RMAX-1)
- Initialize Lists[i, j] as a linked list
- For (i=0 to SongNumber-1)
- Add i to Lists[0, Rating(i)-1]
- For (i=0 to TMAX-1)
- For (j=0 to RMAX-1)
- Shuffle Lists[i, j]
- NextSong:
- // Randomly choose a list, regarding the amount of tickets
- rnd = Random from 1 to (TMAX * (TMAX+1) / 2)
- i = 1
- While ((i * (i+1) / 2) < rnd)
- i = i+1
- i = i-1
- j = Random from 0 to RMAX-1
- // Extract the first element from the list
- next_song = Lists[i, j].First
- Lists[i, j].RemoveFirst
- // Update the tickets of all lists by simply moving the lists around in the matrix
- For (i=TMAX-1 downto 0)
- For (j=0 to RMAX-1)
- new_i = Min(TMAX-1, i+j+1)
- Lists[new_i, j].Concat(Lists[i, j])
- Lists[i, j].Clear
- Add next_song to Lists[0, Rating(next_song)]
- Return next_song
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement