| 44 | /// Generate random values that can be packed within the given bit width. |
| 45 | template <typename Uint> |
| 46 | std::vector<Uint> GenerateRandomValuesForPacking(int num_values, int bit_width) { |
| 47 | constexpr uint32_t kSeed = 3214; |
| 48 | |
| 49 | num_values = std::max(1, num_values); // We need a valid pointer for size 0 |
| 50 | std::vector<Uint> out(num_values); |
| 51 | |
| 52 | if (bit_width == 0) { |
| 53 | return out; |
| 54 | } |
| 55 | |
| 56 | if constexpr (std::is_same_v<Uint, bool>) { |
| 57 | random_is_valid(num_values, 0.5, &out, kSeed); |
| 58 | } else { |
| 59 | const uint64_t max = bit_util::LeastSignificantBitMask<uint64_t, true>(bit_width); |
| 60 | rand_uniform_int(out.size(), kSeed, /* min= */ decltype(max){0}, max, out.data()); |
| 61 | } |
| 62 | return out; |
| 63 | } |
| 64 | |
| 65 | /// Convenience wrapper to unpack into a vector |
| 66 | template <typename Int> |
nothing calls this directly
no test coverage detected