You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

random_state.h 931 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * \file dnn/test/common/random_state.h
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #pragma once
  12. #include <random>
  13. namespace megdnn {
  14. namespace test {
  15. class RandomState {
  16. public:
  17. static std::mt19937& generator() { return instance()->m_generator; }
  18. static void reset() { instance()->m_generator.seed(m_seed); }
  19. private:
  20. RandomState() : m_generator(m_seed) {}
  21. std::mt19937 m_generator;
  22. const static int m_seed = 42;
  23. static RandomState* instance() { return &m_instance; }
  24. static RandomState m_instance;
  25. };
  26. } // namespace test
  27. } // namespace megdnn
  28. // vim: syntax=cpp.doxygen