PolicyManager: New PRNG to use together with the RandomProvider's seed.

The RandomProvider gives you a single random value that you can use
to generate more unsecure random numbers on policies in a
deterministic way.

BUG=chromium:358269
TEST=Unittest added.

Change-Id: Ie344014c55cc56e7dbdf3ce679eb3ca37be52678
Reviewed-on: https://chromium-review.googlesource.com/197441
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/prng.h b/policy_manager/prng.h
new file mode 100644
index 0000000..2922e9f
--- /dev/null
+++ b/policy_manager/prng.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_PRNG_H_
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_PRNG_H_
+
+#include <cstdlib>
+
+#include <base/basictypes.h>
+
+namespace chromeos_policy_manager {
+
+// An unsecure Pseudo-Random Number Generator class based on rand_r(3), which
+// is thread safe and doesn't interfere with other calls to rand().
+class PRNG {
+ public:
+  // Creates the object using the passed |seed| value as the initial state.
+  explicit PRNG(unsigned int seed) : state_(seed) {}
+
+  // Returns a pseudo-random integer in the range [0, RAND_MAX].
+  int rand() { return rand_r(&state_); }
+
+ private:
+  // The internal state of the PRNG.
+  unsigned int state_;
+
+  DISALLOW_COPY_AND_ASSIGN(PRNG);
+};
+
+}  // namespace chromeos_policy_manager
+
+#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_PRNG_H_