From 3b68fb2a03e4bdeb3e59ffc21e3f97b9d6f568ef Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 26 Feb 2011 17:59:34 +0000 Subject: [PATCH] add missing files --- include/libtorrent/random.hpp | 7 +++++++ src/random.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 include/libtorrent/random.hpp create mode 100644 src/random.cpp diff --git a/include/libtorrent/random.hpp b/include/libtorrent/random.hpp new file mode 100644 index 000000000..f45f1caf0 --- /dev/null +++ b/include/libtorrent/random.hpp @@ -0,0 +1,7 @@ +#include + +namespace libtorrent +{ + void random_seed(boost::uint32_t v); + boost::uint32_t random(); +} diff --git a/src/random.cpp b/src/random.cpp new file mode 100644 index 000000000..84a817615 --- /dev/null +++ b/src/random.cpp @@ -0,0 +1,30 @@ +#include "libtorrent/random.hpp" + +namespace libtorrent +{ + + namespace + { + uint32_t x = 123456789; + } + + void random_seed(boost::uint32_t v) + { + x = v; + } + + // this is an xorshift random number generator + // see: http://en.wikipedia.org/wiki/Xorshift + boost::uint32_t random() + { + static uint32_t y = 362436069; + static uint32_t z = 521288629; + static uint32_t w = 88675123; + uint32_t t; + + t = x ^ (x << 11); + x = y; y = z; z = w; + return w = w ^ (w >> 19) ^ (t ^ (t >> 8)); + } +} +