Commit 1845b93d authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang: random_shuffle -> shuffle

There is no std::random_shuffle on `MSVC /std:c++20` because it was removed in C++17:

    golang/runtime/libgolang.cpp(946): error C2039: 'random_shuffle': is not a member of 'std'
    z:\home\kirr\src\tools\go\pygo-win\BuildTools\vc\tools\msvc\14.35.32215\include\random(34): note: see declaration of 'std'
    golang/runtime/libgolang.cpp(946): error C3861: 'random_shuffle': identifier not found

    https://en.cppreference.com/w/cpp/algorithm/random_shuffle
parent 35ed2492
...@@ -900,6 +900,13 @@ template<> int _chanselect2</*onstack=*/true> (const _selcase *, int, const vect ...@@ -900,6 +900,13 @@ template<> int _chanselect2</*onstack=*/true> (const _selcase *, int, const vect
template<> int _chanselect2</*onstack=*/false>(const _selcase *, int, const vector<int>&); template<> int _chanselect2</*onstack=*/false>(const _selcase *, int, const vector<int>&);
static int __chanselect2(const _selcase *, int, const vector<int>&, _WaitGroup*); static int __chanselect2(const _selcase *, int, const vector<int>&, _WaitGroup*);
// PRNG for select.
// TODO consider switching to xoroshiro or wyrand if speed is an issue
// https://thompsonsed.co.uk/random-number-generators-for-c-performance-tested
// https://nullprogram.com/blog/2017/09/21/
static std::random_device _devrand;
static thread_local std::mt19937 _t_rng(_devrand());
// _chanselect executes one ready send or receive channel case. // _chanselect executes one ready send or receive channel case.
// //
// if no case is ready and default case was provided, select chooses default. // if no case is ready and default case was provided, select chooses default.
...@@ -926,7 +933,7 @@ int _chanselect(const _selcase *casev, int casec) { ...@@ -926,7 +933,7 @@ int _chanselect(const _selcase *casev, int casec) {
vector<int> nv(casec); // n -> n(case) TODO -> caller stack-allocate nv vector<int> nv(casec); // n -> n(case) TODO -> caller stack-allocate nv
for (int i=0; i <casec; i++) for (int i=0; i <casec; i++)
nv[i] = i; nv[i] = i;
std::random_shuffle(nv.begin(), nv.end()); std::shuffle(nv.begin(), nv.end(), _t_rng);
// first pass: poll all cases and bail out in the end if default was provided // first pass: poll all cases and bail out in the end if default was provided
int ndefault = -1; int ndefault = -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment