StartRandom() Now uses a linear shuffle instead of an exchange shuffle, so the distribution of songs should be as good as rand().
This commit is contained in:
@@ -1230,23 +1230,21 @@ void MusicWheel::StartRoulette()
|
||||
void MusicWheel::StartRandom()
|
||||
{
|
||||
/* Shuffle the roulette wheel. */
|
||||
//unsigned total = m_WheelItemDatas[SORT_ROULETTE].size();
|
||||
//for(unsigned i = 0; i < total; ++i)
|
||||
// swap(m_WheelItemDatas[SORT_ROULETTE][i], m_WheelItemDatas[SORT_ROULETTE][rand() % total]);
|
||||
/*Linear shuffle means that we shuffle the deck from the beginning to end,
|
||||
but never switch a song from the end with one < i. This method gives an
|
||||
even distribution for any number of songs less than RAND_MAX.*/
|
||||
unsigned total = m_WheelItemDatas[SORT_ROULETTE].size();
|
||||
for(unsigned i = 0; i < total; ++i)
|
||||
swap(m_WheelItemDatas[SORT_ROULETTE][i], m_WheelItemDatas[SORT_ROULETTE][(rand() % (total-i))+i]);
|
||||
|
||||
//SetOpenGroup("", SongSortOrder(SORT_ROULETTE));
|
||||
SetOpenGroup("", SongSortOrder(SORT_ROULETTE));
|
||||
|
||||
//m_Moving = -1;
|
||||
//m_TimeBeforeMovingBegins = 0;
|
||||
//m_SpinSpeed = 1.0f/ROULETTE_SWITCH_SECONDS;
|
||||
//m_SpinSpeed *= 20.0f; /* faster! */
|
||||
|
||||
|
||||
//Simplify Random to make it more random than previously
|
||||
m_Moving = -1;
|
||||
m_TimeBeforeMovingBegins = 0;
|
||||
m_SpinSpeed = 1.0f/ROULETTE_SWITCH_SECONDS;
|
||||
m_SpinSpeed *= 20.0f; /* faster! */
|
||||
m_WheelState = STATE_RANDOM_SPINNING;
|
||||
|
||||
SelectSong(SONGMAN->GetRandomSong());
|
||||
|
||||
this->Select();
|
||||
RebuildMusicWheelItems();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user