Code Monkey home page Code Monkey logo

pseudo-random-number-generator-lfsr-algorithm's Introduction

Pseudo-Random-Number-Generator-LFSR-Algorithm

A pseudo-number generator produces numbers that are random but deterministic. These are pseudorandom because the following numbers can be determined algorithmically if the seed value is known. The linear feedback shift register (LFSR) is one of the more widely used algorithms to implement this.

How it works

  • A shift right function and an XOR or XNOR logic gate can be combined so as to implement an LFSR.

image

At each clock cycle, the bits in the shift register are shifted one position to the right. The value of the feedback bit is computed as the exclusive-or (XOR) of one or more of the bits in the register, as specified by the feedback taps. The bits in the LFSR state that influence the input are called taps. The feedback bit is then added to the leftmost position of the register, and the contents of the register form the next state of the LFSR.

image

  • The XOR positions and taps are defined by the feedback/characteristic polynomial.
  • The feedback polynomial is a mathematical equation that determines the next value in the sequence based on the current state of the LFSR. In simple terms, the feedback polynomial is like a set of rules that tell the LFSR how to generate its output sequence. The coefficients of the polynomial represent the taps (or positions) in the shift register that contribute to the next value in the sequence. For example, an 8-bit LFSR, the feedback polynomial isπ‘₯8+π‘₯6+π‘₯5+π‘₯4+1=0. Hence, outputs of flipflops 8,6,5,4 are summed via XNOR gates and fed back into the first flip-flop.
  • The seed in a Pseudo Random Number Generator (PRNG) implemented using a Linear Feedback Shift Register (LFSR) is the initial state of the LFSR. The seed determines the starting point of the sequence generated by the PRNG, and as a result, affects the entire sequence of numbers produced. A carefully chosen seed can ensure that the sequence produced by the PRNG has desired properties, such as good randomness, long cycle length, or a specific pattern.

LFSR output streams are said to be deterministic. If the present state and the positions of the XOR gates in the LFSR are known, the next state can be predicted. This is not possible with truly random events. With maximal-length LFSRs, it is much easier to compute the next state, as there are only an easily limited number of them for each length.

Output

image

image

Implementation in Circuit-Verse

image

In the implementation of the circuit in CircuitVerse, the seed or the initial state can be set by making the reset=1, then pre-setting the bits to the desired seed. The sequence of random number generated will change depending on the this initial state. The change in values of outputs from the DFFs can be observed after every clock cycle.

Circuit Verse Implementation Link

pseudo-random-number-generator-lfsr-algorithm's People

Contributors

amri-tah avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.