Implement a pseudo-random number generator based on the LFSR method. The polynomial should be provided by the user as a parameter. The program should generate bits "indefinitely" until the user stops the algorithm.
Web app in C#
aspx.cs:
protected void generate_Click(object sender, EventArgs e) {
string polynomial = tb_polynomial.Text;
UInt32 tab = Convert.ToUInt32(tb_polynomial.Text, 2);
UInt32 periodsToDO = UInt32.Parse(tb_NumberofCycles.Text);
UInt32 start_state = tab;
UInt32 lfsr = start_state;
UInt32 period = 0;
do {
UInt32 lsb = lfsr & 1;
lfsr >>= 1;
if (lsb > 0)
lfsr ^= tab;
++period;
if (lfsr == start_state)
lfsr = start_state;
} while (period < periodsToDO);
lb_generator.Text = "Made for " + polynomial;
}
.aspx:
<h2>xx</h2>
<div>
<asp:Label ID="Label10" runat="server" Text="Enter a polynomial"></asp:Label>
<asp:TextBox ID="tb_polynomial" runat="server"></asp:TextBox>
<br />
<asp:Button ID="generuj" runat="server" Text="Generate" OnClick="generate_Click" />
</div>
<div> Number of cycles to be performed: <asp:TextBox ID="tb_iloscCykli" TextMode="Number" runat="server"></asp:TextBox>
<asp:Label ID="lb_generator" runat="server" Text="..."></asp:Label>
</div>
I don't know if I fulfilled the last requirement correctly: the program should generate bits "indefinitely" until the user stops the algorithm. Can I get some tip? And is the overall solution in line with the assumptions?