Linear Feedback Shift Register

Size
2,197 Kb
Views
10,120

How do I make an linear feedback shift register?

What is a linear feedback shift register? How do you make a linear feedback shift register? This script and codes were developed by Sarah Cartwright on 05 December 2022, Monday.

Linear Feedback Shift Register Previews

Linear Feedback Shift Register - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Linear Feedback Shift Register</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!--<div id="out"></div>-->
This Pen does nothing on its own - it is used in other pens. <script src="js/index.js"></script>
</body>
</html>

Linear Feedback Shift Register - Script Codes CSS Codes

body { padding: 10px; margin: 0px; background: #2e2e2e; color: #909090; font: 12px arial, sans-serif;
}

Linear Feedback Shift Register - Script Codes JS Codes

//Leftmost bit can be UP TO 32 bits..... 0 to 31.
function linearFeedbackShiftRegister(seed, taps, leftmostBitIndex) { var tapDefs = taps.map(function(tap, i) { return 'var tapBit' + i + ' = (value >> ' + tap + ') & 1;' }).join('\n'); var tapXOR = taps.map(function(tap, i) { return 'tapBit' + i; }).join(' ^ '); var body = '' + 'var value = ' + seed + ' >>> 0;\n' + 'return function() { \n' + tapDefs + ' \n' + 'var leftmostBit = ' + tapXOR + '; \n' + 'return (value = ((leftmostBit << ' + leftmostBitIndex + ') | (value >>> 1)) >>> 0); \n' + '} \n'; var fn = new Function(body); return attachRandomNumberAPI(leftmostBitIndex, fn());
}
function attachRandomNumberAPI(leftmostBitIndex, fn) { var max = parseInt(Array(leftmostBitIndex+2).join(1), 2); fn.maxValue = max; for(var runSome=0; runSome < leftmostBitIndex * 50; runSome++) fn(); fn.random = function() { return (fn() / max); } return fn;
}
function tetrisLSFR() { //Tetris seed, 16 bits. Range 0-65535) return linearFeedbackShiftRegister(0x8988, [1, 9], 31);
}
function randomSeededLSFR() { //return linearFeedbackShiftRegister(0x8988, [1, 9], 31); return linearFeedbackShiftRegister(Math.random() * 10000000 >>> 0, [16,15,13,4], 31);
}
// Test.
/*
var o = "";
randGen = randomSeededLSFR();
for(var i = 0; i < 100; i++){ o = o + randGen.random() + "<br>";
}
document.getElementById("out").innerHTML = o;
*/
Linear Feedback Shift Register - Script Codes
Linear Feedback Shift Register - Script Codes
Home Page Home
Developer Sarah Cartwright
Username SarahC
Uploaded December 05, 2022
Rating 3
Size 2,197 Kb
Views 10,120
Do you need developer help for Linear Feedback Shift Register?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Sarah Cartwright (SarahC) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!