OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/http2/tools/http2_random.h" |
| 6 |
| 7 #include <limits> |
| 8 #include <memory> |
| 9 |
| 10 #include "base/rand_util.h" |
| 11 |
| 12 namespace net { |
| 13 namespace test { |
| 14 |
| 15 bool Http2Random::OneIn(int n) { |
| 16 return base::RandGenerator(n) == 0; |
| 17 } |
| 18 |
| 19 int32_t Http2Random::Uniform(int32_t n) { |
| 20 return base::RandGenerator(n); |
| 21 } |
| 22 |
| 23 uint8_t Http2Random::Rand8() { |
| 24 return base::RandGenerator( |
| 25 static_cast<uint64_t>(std::numeric_limits<uint8_t>::max()) + 1); |
| 26 } |
| 27 |
| 28 uint16_t Http2Random::Rand16() { |
| 29 return base::RandGenerator( |
| 30 static_cast<uint64_t>(std::numeric_limits<uint16_t>::max()) + 1); |
| 31 } |
| 32 |
| 33 uint32_t Http2Random::Rand32() { |
| 34 return base::RandGenerator( |
| 35 static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1); |
| 36 } |
| 37 |
| 38 uint64_t Http2Random::Rand64() { |
| 39 return base::RandUint64(); |
| 40 } |
| 41 |
| 42 int32_t Http2Random::Next() { |
| 43 return Rand32(); |
| 44 } |
| 45 |
| 46 int32_t Http2Random::Skewed(int max_log) { |
| 47 const uint32_t base = Rand32() % (max_log + 1); |
| 48 const uint32_t mask = ((base < 32) ? (1u << base) : 0u) - 1u; |
| 49 return Rand32() & mask; |
| 50 } |
| 51 |
| 52 std::string Http2Random::RandString(int length) { |
| 53 std::unique_ptr<char[]> buffer(new char[length]); |
| 54 base::RandBytes(buffer.get(), length); |
| 55 return std::string(buffer.get(), length); |
| 56 } |
| 57 |
| 58 } // namespace test |
| 59 } // namespace net |
OLD | NEW |