source: Deliverables/D4.1/GCC/LFSR.c @ 557

Last change on this file since 557 was 182, checked in by mulligan, 9 years ago

Linear feedback shift register (random number generator) example added.

File size: 305 bytes
Line 
1#include "stdio.h"
2
3unsigned int lfsr(unsigned int seed)
4{
5  unsigned int l = seed;
6  unsigned int period = 0;
7  do {
8    l = (l >> 1) ^ (-(int)(l & 1u) & 0xB400u);
9    ++period;
10  } while(l != 0xACE1u);
11  return l;
12}
13
14int main()
15{
16  unsigned int rand = lfsr(0xACE1u);
17  printf("%d", rand);
18  return 0;
19}
Note: See TracBrowser for help on using the repository browser.