Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace std::random_shuffle with std::shuffle #5145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/karts/kart_properties_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ KartPropertiesManager *kart_properties_manager=0;
std::vector<std::string> KartPropertiesManager::m_kart_search_path;

/** Constructor, only clears internal data structures. */
KartPropertiesManager::KartPropertiesManager()
KartPropertiesManager::KartPropertiesManager() : m_random_number_generator(std::random_device{}())
{
m_all_groups.clear();
} // KartPropertiesManager
Expand Down Expand Up @@ -601,8 +601,8 @@ void KartPropertiesManager::getRandomKartList(int count,

assert(random_kart_queue.size() > 0);

std::random_shuffle(random_kart_queue.begin(),
random_kart_queue.end() );
std::shuffle(random_kart_queue.begin(),
random_kart_queue.end(), m_random_number_generator);
}

while (count > 0 && random_kart_queue.size() > 0)
Expand Down
3 changes: 3 additions & 0 deletions src/karts/kart_properties_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "utils/ptr_vector.hpp"
#include <map>
#include <memory>
#include <random>
#include <set>

#include "network/remote_kart_info.hpp"
Expand Down Expand Up @@ -70,6 +71,8 @@ class KartPropertiesManager: public NoCopy
std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_kart_type_characteristics;
std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;

std::mt19937 m_random_number_generator;

protected:

typedef PtrVector<KartProperties> KartPropertiesVector;
Expand Down
6 changes: 3 additions & 3 deletions src/modes/three_strikes_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
//-----------------------------------------------------------------------------
/** Constructor. Sets up the clock mode etc.
*/
ThreeStrikesBattle::ThreeStrikesBattle() : WorldWithRank()
ThreeStrikesBattle::ThreeStrikesBattle() : WorldWithRank(), m_random_number_generator(std::random_device{}())
{
WorldStatus::setClockMode(CLOCK_CHRONO);
m_use_highscores = false;
Expand Down Expand Up @@ -684,8 +684,8 @@ void ThreeStrikesBattle::loadCustomModels()
}

// Find random nodes to pre-spawn spare tire karts
std::random_shuffle(sta_possible_nodes.begin(),
sta_possible_nodes.end());
std::shuffle(sta_possible_nodes.begin(),
sta_possible_nodes.end(), m_random_number_generator);

// Compute a random kart list
std::vector<std::string> sta_list;
Expand Down
4 changes: 3 additions & 1 deletion src/modes/three_strikes_battle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "modes/world_with_rank.hpp"
#include "tracks/track_object.hpp"
#include "states_screens/race_gui_base.hpp"

#include <random>
#include <string>

class PhysicalObject;
Expand Down Expand Up @@ -92,6 +92,8 @@ class ThreeStrikesBattle : public WorldWithRank
std::vector<AbstractKart*> m_spare_tire_karts;
int m_next_sta_spawn_ticks;

std::mt19937 m_random_number_generator;

public:
/** Used to show a nice graph when battle is over */
struct BattleEvent
Expand Down
4 changes: 2 additions & 2 deletions src/states_screens/easter_egg_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const char ALL_TRACK_GROUPS_ID[] = "all";

// -----------------------------------------------------------------------------

EasterEggScreen::EasterEggScreen() : Screen("easter_egg.stkgui")
EasterEggScreen::EasterEggScreen() : Screen("easter_egg.stkgui"), m_random_number_generator(std::random_device{}())
{
}

Expand Down Expand Up @@ -288,7 +288,7 @@ void EasterEggScreen::buildTrackList()
0 /* no badge */, IconButtonWidget::ICON_PATH_TYPE_RELATIVE);

tracks_widget->updateItemDisplay();
std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() );
std::shuffle( m_random_track_list.begin(), m_random_track_list.end(), m_random_number_generator );
}

// -----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/states_screens/easter_egg_screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "guiengine/screen.hpp"
#include <deque>
#include <random>

namespace GUIEngine { class Widget; }

Expand All @@ -31,6 +32,8 @@ class EasterEggScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingle
{
friend class GUIEngine::ScreenSingleton<EasterEggScreen>;

std::mt19937 m_random_number_generator;

EasterEggScreen();

/** adds the tracks from the current track group into the tracks ribbon */
Expand Down
2 changes: 1 addition & 1 deletion src/states_screens/online/tracks_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ void TracksScreen::buildTrackList()
IconButtonWidget::ICON_PATH_TYPE_RELATIVE);

tracks_widget->updateItemDisplay();
std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() );
std::shuffle( m_random_track_list.begin(), m_random_track_list.end(), m_random_number_generator );
} // buildTrackList

// -----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/states_screens/online/tracks_screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <deque>
#include <limits>
#include <random>
#include <string>
#include <vector>

Expand Down Expand Up @@ -88,7 +89,8 @@ class TracksScreen : public GUIEngine::Screen,

void voteForPlayer();

TracksScreen() : Screen("tracks.stkgui")
std::mt19937 m_random_number_generator;
TracksScreen() : Screen("tracks.stkgui"), m_random_number_generator(std::random_device{}())
{
m_network_tracks = false;
m_quit_server = false;
Expand Down
2 changes: 1 addition & 1 deletion src/states_screens/tracks_and_gp_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void TracksAndGPScreen::buildTrackList()
IconButtonWidget::ICON_PATH_TYPE_RELATIVE);

tracks_widget->updateItemDisplay();
std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() );
std::shuffle( m_random_track_list.begin(), m_random_track_list.end(), m_random_number_generator );
} // buildTrackList

// -----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/states_screens/tracks_and_gp_screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "guiengine/screen.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include <deque>
#include <random>

namespace GUIEngine { class Widget; }

Expand All @@ -37,7 +38,8 @@ class TracksAndGPScreen : public GUIEngine::Screen,
private:
GUIEngine::TextBoxWidget* m_search_box;

TracksAndGPScreen() : Screen("tracks_and_gp.stkgui") {}
std::mt19937 m_random_number_generator;
TracksAndGPScreen() : Screen("tracks_and_gp.stkgui"), m_random_number_generator(std::random_device{}()) {}

/** adds the tracks from the current track group into the tracks ribbon */
void buildTrackList();
Expand Down
2 changes: 1 addition & 1 deletion src/tracks/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool Track::m_dont_load_navmesh = false;
std::atomic<Track*> Track::m_current_track[PT_COUNT];

// ----------------------------------------------------------------------------
Track::Track(const std::string &filename)
Track::Track(const std::string &filename) : m_random_number_generator(std::random_device{}())
{
#ifdef DEBUG
m_magic_number = 0x17AC3802;
Expand Down
4 changes: 3 additions & 1 deletion src/tracks/track.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <algorithm>
#include <atomic>
#include <memory>
#include <random>
#include <string>
#include <vector>

Expand Down Expand Up @@ -138,6 +139,7 @@ class Track

std::vector<Subtitle> m_subtitles;

std::mt19937 m_random_number_generator;
/** Start transforms of karts (either the default, or the ones taken
* from the scene file). */
AlignedArray<btTransform> m_start_transforms;
Expand Down Expand Up @@ -562,7 +564,7 @@ class Track
*/
void shuffleStartTransforms()
{
std::random_shuffle(m_start_transforms.begin(), m_start_transforms.end());
std::shuffle(m_start_transforms.begin(), m_start_transforms.end(), m_random_number_generator);
}
// ------------------------------------------------------------------------
/** Sets pointer to the aabb of this track. */
Expand Down
Loading