data.random.lfsr


template <auto Width>
inline uint<Width> lfsr(uint<Width> seed) §

A Linear Feedback Shift Register, which is a simple type of pseudo-random number generator. lfsr_random uses this function to generate successive pseudo-random numbers: pass any non-zero seed value into the initial call to the lfsr method, and then pass the returned value back in as the new seed on successive calls.

The polynomial used for this LFSR will visit every value except zero. Never use zero as a seed, the LFSR will always return zero for a zero input. If you are looking for a traditional random number generator, this may not be a good choice because the LFSR will not revisit a value until it has visited all other 2N − 2 values.

Parameters

  • auto Width
    

    The bit-width of the LFSR. Widths from 2 to 32 inclusive are supported.

template <auto SeedWidth>
class lfsr_random §

A stateful pseudo-random number generator using a linear feedback shift register (LFSR).

The polynomial used for this LFSR will visit every value except zero. Never use zero as a seed, the LFSR will always return zero for a zero input. If you are looking for a traditional random number generator, this may not be a good choice because the LFSR will not revisit a value until it has visited all other 2N − 2 values.

Parameters

  • auto SeedWidth
    

    The bit-width of the LFSR. Widths from 2 to 32 inclusive are supported.

Aliases

  • using value_t = uint<SeedWidth> §
    

Methods

  • lfsr_random::value_t next(optional<uint<SeedWidth>> seed) §
    

    Get the next random number in the sequence, optionally seeding the random number generator first. Do not use zero for the seed value.

    Arguments

    • optional<uint<SeedWidth>> seed
      

      If is_valid then seed the generator, otherwise ignore.