SHOW:
|
|
- or go back to the newest paste.
1 | Let Rating(i) be the user rating of the ith song, bounded by 0 < Rating(i) < RMAX | |
2 | Let TMAX be the maximum amount of tickets a song can have | |
3 | Let Lists be a matrix of size TMAX x RMAX | |
4 | ||
5 | Initialization: | |
6 | For (i=0 to TMAX-1) | |
7 | For (j=0 to RMAX-1) | |
8 | Initialize Lists[i, j] as a linked list | |
9 | ||
10 | For (i=0 to SongNumber-1) | |
11 | Add i to Lists[0, Rating(i)-1] | |
12 | ||
13 | For (i=0 to TMAX-1) | |
14 | For (j=0 to RMAX-1) | |
15 | Shuffle Lists[i, j] | |
16 | ||
17 | ||
18 | ||
19 | NextSong: | |
20 | // Randomly choose a list, regarding the amount of tickets | |
21 | rnd = Random from 1 to (TMAX * (TMAX+1) / 2) | |
22 | i = 1 | |
23 | While ((i * (i+1) / 2) < rnd) | |
24 | i = i+1 | |
25 | i = i-1 | |
26 | ||
27 | j = Random from 0 to RMAX-1 | |
28 | ||
29 | // Extract the first element from the list | |
30 | next_song = Lists[i, j].First | |
31 | Lists[i, j].RemoveFirst | |
32 | ||
33 | // Update the tickets of all lists by simply moving the lists around in the matrix | |
34 | For (i=TMAX-1 downto 0) | |
35 | For (j=0 to RMAX-1) | |
36 | new_i = Min(TMAX-1, i+j+1) | |
37 | Lists[new_i, j].Concat(Lists[i, j]) | |
38 | Lists[i, j].Clear | |
39 | ||
40 | Add next_song to Lists[0, Rating(next_song)] | |
41 | ||
42 | Return next_song |