Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 } | 212 } |
| 213 return true; | 213 return true; |
| 214 } | 214 } |
| 215 | 215 |
| 216 std::string CreateRandomString(size_t len) { | 216 std::string CreateRandomString(size_t len) { |
| 217 std::string str; | 217 std::string str; |
| 218 CreateRandomString(len, &str); | 218 CreateRandomString(len, &str); |
| 219 return str; | 219 return str; |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool CreateRandomString(size_t len, | 222 static bool CreateRandomString(size_t len, |
|
joachim
2016/07/01 22:27:34
Function is not exposed through header, so I chane
| |
| 223 const char* table, int table_size, | 223 const char* table, int table_size, |
| 224 std::string* str) { | 224 std::string* str) { |
| 225 str->clear(); | 225 str->clear(); |
| 226 // Avoid biased modulo division below. | |
| 227 if (256 % table_size) { | |
| 228 LOG(LS_ERROR) << "Table size must divide 256 evenly!"; | |
| 229 return false; | |
| 230 } | |
| 226 std::unique_ptr<uint8_t[]> bytes(new uint8_t[len]); | 231 std::unique_ptr<uint8_t[]> bytes(new uint8_t[len]); |
| 227 if (!Rng().Generate(bytes.get(), len)) { | 232 if (!Rng().Generate(bytes.get(), len)) { |
| 228 LOG(LS_ERROR) << "Failed to generate random string!"; | 233 LOG(LS_ERROR) << "Failed to generate random string!"; |
| 229 return false; | 234 return false; |
| 230 } | 235 } |
| 231 str->reserve(len); | 236 str->reserve(len); |
| 232 for (size_t i = 0; i < len; ++i) { | 237 for (size_t i = 0; i < len; ++i) { |
| 233 str->push_back(table[bytes[i] % table_size]); | 238 str->push_back(table[bytes[i] % table_size]); |
| 234 } | 239 } |
| 235 return true; | 240 return true; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 } while (id == 0); | 304 } while (id == 0); |
| 300 return id; | 305 return id; |
| 301 } | 306 } |
| 302 | 307 |
| 303 double CreateRandomDouble() { | 308 double CreateRandomDouble() { |
| 304 return CreateRandomId() / (std::numeric_limits<uint32_t>::max() + | 309 return CreateRandomId() / (std::numeric_limits<uint32_t>::max() + |
| 305 std::numeric_limits<double>::epsilon()); | 310 std::numeric_limits<double>::epsilon()); |
| 306 } | 311 } |
| 307 | 312 |
| 308 } // namespace rtc | 313 } // namespace rtc |
| OLD | NEW |