Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 1
    be great for this to have more comments on this code to explain whats going on here for people still learning bitwise. I'm getting throw off because if "lfsr" is defined by the constant every time the function is called and then bitwised by another constant, how is this generating random numbers. why is the definition for LFSR_MASK so complex if its just a constant? please help? Commented Feb 4, 2019 at 22:11
  • @dprogramz: In C, the static keyword in the declaration protects against just what you are worried about--the initialization with the constant only happens once on the initial declaration of the function, and the changing lfsr state is maintained through successive calls to the function. The bit-shifting definition of LFSR_MASK looks complicated, but it is easier to check, explain, change, and maintain than constants like 0b10100010100000000000000000000000UL The actual selection of the mask is more complicated, so see the refs. Commented May 13, 2019 at 3:53
  • 1
    Thanks for the reply, that makes total sense now. I had a misunderstanding of the use to the Static keyword, but it's much more clearer now how it functions, thanks again! Commented May 20, 2019 at 15:50