From: @jonyguo Reviewed-by: @heleiwang,@liucunwei Signed-off-by: @liucunweipull/15242/MERGE
| @@ -17,6 +17,9 @@ | |||||
| #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_RANDOM_H_ | #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_RANDOM_H_ | ||||
| #if defined(_WIN32) || defined(_WIN64) | #if defined(_WIN32) || defined(_WIN64) | ||||
| #ifndef _CRT_RAND_S | |||||
| #define _CRT_RAND_S | |||||
| #endif | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #endif | #endif | ||||
| #include <chrono> | #include <chrono> | ||||
| @@ -14,6 +14,7 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "minddata/dataset/util/random.h" | |||||
| #include "minddata/mindrecord/include/shard_writer.h" | #include "minddata/mindrecord/include/shard_writer.h" | ||||
| #include "utils/ms_utils.h" | #include "utils/ms_utils.h" | ||||
| #include "minddata/mindrecord/include/common/shard_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::vector<int> v_list(shard_count_); | ||||
| std::iota(v_list.begin(), v_list.end(), 0); | 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::shuffle(v_list.begin(), v_list.end(), g); | ||||
| std::unordered_set<int> set(v_list.begin(), v_list.begin() + remains); | std::unordered_set<int> set(v_list.begin(), v_list.begin() + remains); | ||||
| @@ -14,6 +14,7 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "minddata/dataset/util/random.h" | |||||
| #include "minddata/mindrecord/include/shard_task.h" | #include "minddata/mindrecord/include/shard_task.h" | ||||
| #include "utils/ms_utils.h" | #include "utils/ms_utils.h" | ||||
| #include "minddata/mindrecord/include/common/shard_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::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); | std::uniform_int_distribution<> dis(0, task_list_.size() - 1); | ||||
| return task_list_[dis(gen)]; | return task_list_[dis(gen)]; | ||||
| } | } | ||||