Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Linear-feedback shift register
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Xorshift LFSRs == {{Main | Xorshift}} As shown by [[George Marsaglia]]<ref name="marsaglia">{{cite journal | first=George | last=Marsaglia | author-link=George Marsaglia | title=Xorshift RNGs | journal=[[Journal of Statistical Software]] | volume=8 | issue=14 | date=July 2003 | url=https://www.jstatsoft.org/v08/i14/paper | doi=10.18637/jss.v008.i14| doi-access=free}}</ref> and further analysed by [[Richard P. Brent]],<ref name="brent">{{cite journal | first=Richard P. | last=Brent | author-link=Richard P. Brent | title=Note on Marsaglia's Xorshift Random Number Generators | journal=[[Journal of Statistical Software]] | volume=11 | issue=5 | date=August 2004 | url=https://www.jstatsoft.org/v11/i05/paper | doi=10.18637/jss.v011.i05| doi-access=free| hdl=1885/34049| hdl-access=free}}</ref> linear feedback shift registers can be implemented using XOR and Shift operations. This approach lends itself to fast execution in software because these operations typically map efficiently into modern processor instructions. Below is a [[C (programming language)|C]] code example for a 16-bit maximal-period Xorshift LFSR using the 7,9,13 triplet from John Metcalf:<ref>{{cite web |last1=Metcalf |first1=John |title=16-Bit Xorshift Pseudorandom Numbers in Z80 Assembly |url=http://www.retroprogramming.com/2017/07/xorshift-pseudorandom-numbers-in-z80.html |website=Retro Programming |access-date=5 January 2022|date=22 July 2017}}</ref> <syntaxhighlight lang="c"> #include <stdint.h> unsigned lfsr_xorshift(void) { uint16_t start_state = 0xACE1u; /* Any nonzero start state will work. */ uint16_t lfsr = start_state; unsigned period = 0; do { // 7,9,13 triplet from http://www.retroprogramming.com/2017/07/xorshift-pseudorandom-numbers-in-z80.html lfsr ^= lfsr >> 7; lfsr ^= lfsr << 9; lfsr ^= lfsr >> 13; ++period; } while (lfsr != start_state); return period; } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)