Example #1
0
    // static
    double FieldTrial::HashClientId(const std::string& client_id,
        const std::string& trial_name)
    {
        // SHA-1 is designed to produce a uniformly random spread in its output space,
        // even for nearly-identical inputs, so it helps massage whatever client_id
        // and trial_name we get into something with a uniform distribution, which
        // is desirable so that we don't skew any part of the 0-100% spectrum.
        std::string input(client_id + trial_name);
        unsigned char sha1_hash[SHA1_LENGTH];
        SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()),
            input.size(), sha1_hash);

        COMPILE_ASSERT(sizeof(uint64)<sizeof(sha1_hash), need_more_data);
        uint64* bits = reinterpret_cast<uint64*>(&sha1_hash[0]);

        return BitsToOpenEndedUnitInterval(*bits);
    }
Example #2
0
 double RandDouble()
 {
     return BitsToOpenEndedUnitInterval(RandUint64());
 }