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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 bool CreateRandomString(size_t len, std::string* str) { | 238 bool CreateRandomString(size_t len, std::string* str) { |
239 return CreateRandomString(len, kBase64, 64, str); | 239 return CreateRandomString(len, kBase64, 64, str); |
240 } | 240 } |
241 | 241 |
242 bool CreateRandomString(size_t len, const std::string& table, | 242 bool CreateRandomString(size_t len, const std::string& table, |
243 std::string* str) { | 243 std::string* str) { |
244 return CreateRandomString(len, table.c_str(), | 244 return CreateRandomString(len, table.c_str(), |
245 static_cast<int>(table.size()), str); | 245 static_cast<int>(table.size()), str); |
246 } | 246 } |
247 | 247 |
| 248 bool CreateRandomData(size_t length, void* data) { |
| 249 return Rng().Generate(data, length); |
| 250 } |
| 251 |
248 // Version 4 UUID is of the form: | 252 // Version 4 UUID is of the form: |
249 // xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx | 253 // xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx |
250 // Where 'x' is a hex digit, and 'y' is 8, 9, a or b. | 254 // Where 'x' is a hex digit, and 'y' is 8, 9, a or b. |
251 std::string CreateRandomUuid() { | 255 std::string CreateRandomUuid() { |
252 std::string str; | 256 std::string str; |
253 std::unique_ptr<uint8_t[]> bytes(new uint8_t[31]); | 257 std::unique_ptr<uint8_t[]> bytes(new uint8_t[31]); |
254 if (!Rng().Generate(bytes.get(), 31)) { | 258 if (!Rng().Generate(bytes.get(), 31)) { |
255 LOG(LS_ERROR) << "Failed to generate random string!"; | 259 LOG(LS_ERROR) << "Failed to generate random string!"; |
256 return str; | 260 return str; |
257 } | 261 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } while (id == 0); | 303 } while (id == 0); |
300 return id; | 304 return id; |
301 } | 305 } |
302 | 306 |
303 double CreateRandomDouble() { | 307 double CreateRandomDouble() { |
304 return CreateRandomId() / (std::numeric_limits<uint32_t>::max() + | 308 return CreateRandomId() / (std::numeric_limits<uint32_t>::max() + |
305 std::numeric_limits<double>::epsilon()); | 309 std::numeric_limits<double>::epsilon()); |
306 } | 310 } |
307 | 311 |
308 } // namespace rtc | 312 } // namespace rtc |
OLD | NEW |