blob: fac26538beffb16e63cc94beb8ee5dc3410b9373 [file] [log] [blame]
henrike@webrtc.org47be73b2014-05-13 18:00:261/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Henrik Kjellanderfb3e1b62017-06-29 06:03:0411#ifndef WEBRTC_RTC_BASE_HELPERS_H_
12#define WEBRTC_RTC_BASE_HELPERS_H_
henrike@webrtc.org47be73b2014-05-13 18:00:2613
Henrik Kjellander88b2dd42017-06-29 05:52:5014#include <string>
kjellander19796962017-06-30 17:45:2115#include "webrtc/rtc_base/basictypes.h"
henrike@webrtc.org47be73b2014-05-13 18:00:2616
Henrik Kjellander88b2dd42017-06-29 05:52:5017namespace rtc {
18
19// For testing, we can return predictable data.
20void SetRandomTestMode(bool test);
21
22// Initializes the RNG, and seeds it with the specified entropy.
23bool InitRandom(int seed);
24bool InitRandom(const char* seed, size_t len);
25
26// Generates a (cryptographically) random string of the given length.
27// We generate base64 values so that they will be printable.
28std::string CreateRandomString(size_t length);
29
30// Generates a (cryptographically) random string of the given length.
31// We generate base64 values so that they will be printable.
32// Return false if the random number generator failed.
33bool CreateRandomString(size_t length, std::string* str);
34
35// Generates a (cryptographically) random string of the given length,
36// with characters from the given table. Return false if the random
37// number generator failed.
38// For ease of implementation, the function requires that the table
39// size evenly divide 256; otherwise, it returns false.
40bool CreateRandomString(size_t length, const std::string& table,
41 std::string* str);
42
43// Generates (cryptographically) random data of the given length.
44// Return false if the random number generator failed.
45bool CreateRandomData(size_t length, std::string* data);
46
47// Generates a (cryptographically) random UUID version 4 string.
48std::string CreateRandomUuid();
49
50// Generates a random id.
51uint32_t CreateRandomId();
52
53// Generates a 64 bit random id.
54uint64_t CreateRandomId64();
55
56// Generates a random id > 0.
57uint32_t CreateRandomNonZeroId();
58
59// Generates a random double between 0.0 (inclusive) and 1.0 (exclusive).
60double CreateRandomDouble();
61
62} // namespace rtc
henrike@webrtc.org47be73b2014-05-13 18:00:2663
Henrik Kjellanderfb3e1b62017-06-29 06:03:0464#endif // WEBRTC_RTC_BASE_HELPERS_H_