| // Copyright lowRISC contributors. |
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| // SPDX-License-Identifier: Apache-2.0 |
| #include "sw/device/lib/testing/random.h" |
| #include "sw/device/lib/testing/check.h" |
| * The polynomial co-efficients used in the 32-bit LFSR implementation. |
| * This implementation matches the RTL design at `hw/ip/prim/rtl/prim_lfsr.sv`. |
| const uint32_t kLfsrCoefficients = 0x80000057; |
| uint32_t random_gen32(void) { |
| static uint32_t lfsr = 1; |
| lfsr ^= kLfsrCoefficients; |
| uint32_t random_gen32_range(uint32_t min, uint32_t max) { |
| uint32_t range = max - min; |
| return min + (random_gen32() % (range + 1)); |