Skip to content

Commit

Permalink
Use new random in libmamba
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Jan 15, 2024
1 parent 2ba4665 commit 4f30a25
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
11 changes: 7 additions & 4 deletions libmamba/src/core/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ extern "C"
#include "mamba/core/output.hpp"
#include "mamba/core/run.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/util/environment.hpp"
#include "mamba/util/random.hpp"
#include "mamba/util/string.hpp"

namespace mamba
Expand Down Expand Up @@ -69,7 +69,10 @@ namespace mamba
if (!prefixes_bag.empty())
{
// Pick a random prefix from our bag of prefixes.
const auto selected_prefix_idx = random_int<std::size_t>(0, prefixes_bag.size() - 1);
const auto selected_prefix_idx = util::random_int<std::size_t>(
0,
prefixes_bag.size() - 1
);
const auto selected_prefix_it = std::next(
prefixes_bag.begin(),
static_cast<std::ptrdiff_t>(selected_prefix_idx)
Expand All @@ -80,7 +83,7 @@ namespace mamba
else if (!alt_names.empty())
{
// No more prefixes: we retry the same prefixes but with a different program name.
const auto selected_name_idx = random_int<std::size_t>(0, alt_names.size() - 1);
const auto selected_name_idx = util::random_int<std::size_t>(0, alt_names.size() - 1);
const auto selected_name_it = std::next(
alt_names.begin(),
static_cast<std::ptrdiff_t>(selected_name_idx)
Expand All @@ -96,7 +99,7 @@ namespace mamba
// No prefixes left in the bag nor alternative names, just generate a random prefix
// as a fail-safe.
constexpr std::size_t arbitrary_prefix_length = 8;
selected_prefix = generate_random_alphanumeric_string(arbitrary_prefix_length);
selected_prefix = util::generate_random_alphanumeric_string(arbitrary_prefix_length);
selected_name = program_name;
}

Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ extern "C"
#include "mamba/core/thread_utils.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/fs/filesystem.hpp"
#include "mamba/util/build.hpp"
#include "mamba/util/compare.hpp"
#include "mamba/util/environment.hpp"
#include "mamba/util/random.hpp"
#include "mamba/util/string.hpp"
#include "mamba/util/url.hpp"

Expand Down Expand Up @@ -212,7 +212,7 @@ namespace mamba

do
{
std::string random_file_name = mamba::generate_random_alphanumeric_string(10);
std::string random_file_name = util::generate_random_alphanumeric_string(10);
final_path = temp_path / util::concat(prefix, random_file_name, suffix);
} while (fs::exists(final_path));

Expand Down
6 changes: 3 additions & 3 deletions libmamba/tests/src/core/test_satisfiability_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include "mamba/core/solver.hpp"
#include "mamba/core/subdirdata.hpp"
#include "mamba/core/util.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/fs/filesystem.hpp"
#include "mamba/specs/package_info.hpp"
#include "mamba/util/random.hpp"
#include "mamba/util/string.hpp"

#include "mambatests.hpp"
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace
)
{
const auto tmp_dir = dir_guard(
fs::temp_directory_path() / "mamba/tests" / generate_random_alphanumeric_string(20)
fs::temp_directory_path() / "mamba/tests" / util::generate_random_alphanumeric_string(20)
);
const auto repodata_f = create_repodata_json(tmp_dir.path, packages);

Expand Down Expand Up @@ -379,7 +379,7 @@ namespace
{
// Reusing the cache for all invocation of this funciton for speedup
static const auto tmp_dir = dir_guard(
fs::temp_directory_path() / "mamba/tests" / generate_random_alphanumeric_string(20)
fs::temp_directory_path() / "mamba/tests" / util::generate_random_alphanumeric_string(20)
);

auto prefix_data = expected_value_or_throw(
Expand Down
2 changes: 1 addition & 1 deletion micromamba/src/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "mamba/core/error_handling.hpp"
#include "mamba/core/execution.hpp"
#include "mamba/core/util_os.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/util/random.hpp"

#include "common_options.hpp"

Expand Down

0 comments on commit 4f30a25

Please sign in to comment.