Download tools/mosesdecoder/util/random.cc from Quagmire1/wiki-cased: direct link, hf CLI and curl.
- Browser
- Download file 874 Bytes
-
https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/util/random.cc
- Command line
-
hf download hf://Quagmire1/wiki-cased/tools/mosesdecoder/util/random.cc
-
curl -L -o random.cc https://huggingface.co/Quagmire1/wiki-cased/resolve/main/tools/mosesdecoder/util/random.cc
874 Bytes
| // #include <boost/thread/lock_guard.hpp> | |
| namespace util | |
| { | |
| namespace | |
| { | |
| /** Lock to protect randomizer. | |
| * | |
| * This module is implemented in terms of rand()/srand() from <cstdlib>. | |
| * These functions are standard C, but they're not thread-safe. Scalability | |
| * is not worth much complexity here, so just slap a mutex around it. | |
| */ | |
| boost::mutex rand_lock; | |
| } // namespace | |
| void rand_init(unsigned int seed) | |
| { | |
| boost::lock_guard<boost::mutex> lock(rand_lock); | |
| srand(seed); | |
| } | |
| void rand_init() | |
| { | |
| rand_init(time(NULL)); | |
| } | |
| namespace internal | |
| { | |
| // This is the one call to the actual randomizer. All else is built on this. | |
| int rand_int() | |
| { | |
| boost::lock_guard<boost::mutex> lock(rand_lock); | |
| return std::rand(); | |
| } | |
| } // namespace internal | |
| } // namespace util | |