Skip to content

Commit

Permalink
Replace random
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Jun 26, 2024
1 parent c843514 commit e89210d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Editor/DearImGui/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ void Editor::PetriView::handleArcDestination()
assert(m_mouse.to != nullptr);

// The case where two nodes have the same type is managed by addArc
m_editor.m_net.addArc(*m_mouse.from, *m_mouse.to, random(1, 5));
m_editor.m_net.addArc(*m_mouse.from, *m_mouse.to, randomInt(1, 5));

action->after(m_editor.m_net);
m_editor.m_history.add(std::move(action));
Expand Down
19 changes: 15 additions & 4 deletions src/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif

# include <algorithm> // std::transform
# include <random>

//------------------------------------------------------------------------------
#ifdef __APPLE__
Expand Down Expand Up @@ -66,11 +67,21 @@ std::string osx_get_resources_dir(std::string const& file)
namespace tpne {

//------------------------------------------------------------------------------
float random(int lower, int upper)
int randomInt(int lower, int upper)
{
auto const t = static_cast<unsigned int>(time(NULL));
srand(t);
return float(rand() % (upper - lower + 1)) + float(lower);
static std::random_device rd;
static std::mt19937 gen(rd());
std::uniform_int_distribution<> dist(lower, upper);
return dist(gen);
}

//------------------------------------------------------------------------------
float randomFloat(int lower, int upper)
{
static std::random_device rd;
static std::mt19937 gen(rd());
std::uniform_real_distribution<float> dist(lower, upper);
return dist(gen);
}

//------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/Utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ T rotate(T const& v, float const cos_a, float const sin_a)
}

//------------------------------------------------------------------------------
float random(int lower, int upper);
int randomInt(int lower, int upper);
float randomFloat(int lower, int upper);

//------------------------------------------------------------------------------
//! \brief give the file extension
Expand Down

0 comments on commit e89210d

Please sign in to comment.