Linear Feedback Shift Register (LFSR) is a shift register that can be used to generate random numbers in hardware.

The following code represents an LFSR with equation x^{32}+x^{22}+x^2+x+1

unsigned int pseudo_random(unsigned int seed, int load) {
  static ap_uint<32> lfsr;

  if (load ==1 )
    lfsr = seed;
  bool b_32 = lfsr.get_bit(32-32);
  bool b_22 = lfsr.get_bit(32-22);
  bool b_2 = lfsr.get_bit(32-2);
  bool b_1 = lfsr.get_bit(32-1);
  bool new_bit = b_32 ^ b_22 ^ b_2 ^ b_1;
  lfsr = lfsr >> 1;
  lfsr.set_bit(31, new_bit);

  return lfsr.to_uint();