forked from mindspore-Ecosystem/mindspore
fix: random_device(...) failed in some situation
This commit is contained in:
parent
f4724ea85c
commit
dcab396d96
|
@ -17,6 +17,9 @@
|
|||
#define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_RANDOM_H_
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#ifndef _CRT_RAND_S
|
||||
#define _CRT_RAND_S
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <chrono>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "minddata/dataset/util/random.h"
|
||||
#include "minddata/mindrecord/include/shard_writer.h"
|
||||
#include "utils/ms_utils.h"
|
||||
#include "minddata/mindrecord/include/common/shard_utils.h"
|
||||
|
@ -1156,8 +1157,8 @@ std::vector<std::pair<int, int>> ShardWriter::BreakIntoShards() {
|
|||
|
||||
std::vector<int> v_list(shard_count_);
|
||||
std::iota(v_list.begin(), v_list.end(), 0);
|
||||
std::random_device rd;
|
||||
std::mt19937 g(rd());
|
||||
|
||||
std::mt19937 g = mindspore::dataset::GetRandomDevice();
|
||||
std::shuffle(v_list.begin(), v_list.end(), g);
|
||||
std::unordered_set<int> set(v_list.begin(), v_list.begin() + remains);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "minddata/dataset/util/random.h"
|
||||
#include "minddata/mindrecord/include/shard_task.h"
|
||||
#include "utils/ms_utils.h"
|
||||
#include "minddata/mindrecord/include/common/shard_utils.h"
|
||||
|
@ -65,8 +66,7 @@ std::tuple<TaskType, std::tuple<int, int>, std::vector<uint64_t>, json> &ShardTa
|
|||
}
|
||||
|
||||
std::tuple<TaskType, std::tuple<int, int>, std::vector<uint64_t>, json> &ShardTask::GetRandomTask() {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::mt19937 gen = mindspore::dataset::GetRandomDevice();
|
||||
std::uniform_int_distribution<> dis(0, task_list_.size() - 1);
|
||||
return task_list_[dis(gen)];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue