summaryrefslogtreecommitdiffstats
path: root/base/rand_util.cc
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-10 17:18:53 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-10 17:18:53 +0000
commitedafd4c1a5c906e808e2448810e2099d8dc704b9 (patch)
tree4ccc930c0b9ff8663183ebb6333e9ac990f0e491 /base/rand_util.cc
parent063bb25a11a9258c44d61210dfd98f41e7b4f24a (diff)
downloadchromium_src-edafd4c1a5c906e808e2448810e2099d8dc704b9.zip
chromium_src-edafd4c1a5c906e808e2448810e2099d8dc704b9.tar.gz
chromium_src-edafd4c1a5c906e808e2448810e2099d8dc704b9.tar.bz2
Add one-time randomization support for FieldTrial, and the ability to
disable field trials. I am going to have a need for both soon. Update some documentation about empty trial names, add TrialExists() method and update many call-sites to use this (it simplifies the previous logic which checked for existence and then for non-empty name, which can no longer happen). Refactor a bit in browser_main. While I'm in there and needing base/OWNERS approval, add an OWNERS file for base/metrics that adds jar@chromium.org as an owner for that directory. Initially committed as r84197. Rolled back due to DCHECK in official builds, r84373. Will re-submit with fix. BUG=81750 TEST=base_unittests Review URL: http://codereview.chromium.org/6883102 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84801 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/rand_util.cc')
-rw-r--r--base/rand_util.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/base/rand_util.cc b/base/rand_util.cc
index fc41ce8..4140e9a 100644
--- a/base/rand_util.cc
+++ b/base/rand_util.cc
@@ -25,6 +25,10 @@ int RandInt(int min, int max) {
}
double RandDouble() {
+ return BitsToOpenEndedUnitInterval(base::RandUint64());
+}
+
+double BitsToOpenEndedUnitInterval(uint64 bits) {
// We try to get maximum precision by masking out as many bits as will fit
// in the target type's mantissa, and raising it to an appropriate power to
// produce output in the range [0, 1). For IEEE 754 doubles, the mantissa
@@ -32,7 +36,7 @@ double RandDouble() {
COMPILE_ASSERT(std::numeric_limits<double>::radix == 2, otherwise_use_scalbn);
static const int kBits = std::numeric_limits<double>::digits;
- uint64 random_bits = base::RandUint64() & ((GG_UINT64_C(1) << kBits) - 1);
+ uint64 random_bits = bits & ((GG_UINT64_C(1) << kBits) - 1);
double result = ldexp(static_cast<double>(random_bits), -1 * kBits);
DCHECK_GE(result, 0.0);
DCHECK_LT(result, 1.0);