DSPRelated.com
Forums

LFSR in java

Started by dahawi amer April 1, 2017
hi 
please help me to programmed linear feedback shift register algorithm in java

On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote:
> hi > please help me to programmed linear feedback shift register algorithm in java
i have this code import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; public final class LFSR { private static final int M = 32; private static final int[] TAPS = {1, 2, 11, 31}; private final boolean[] bits = new boolean[M + 1]; public LFSR(int seed) { for(int i = 0; i < M; i++) { bits[i] = (((1 << i) & seed) >>> i) == 1; } } public LFSR() { this((int)System.currentTimeMillis()); } public int nextInt() { int next = 0; for(int i = 0; i < M; i++) { next |= (bits[i] ? 1 : 0) << i; } if (next < 0) next++; bits[M] = false; for(int i = 0; i < TAPS.length; i++) { bits[M] ^= bits[M - TAPS[i]]; } // shift all the registers for(int i = 0; i < M; i++) { bits[i] = bits[i + 1]; } return next; } public double nextDouble() { return ((nextInt() / (Integer.MAX_VALUE + 1.0)) + 1.0) / 2.0; } public static void main(String[] args) { FileWriter fichero = null; PrintWriter pw = null; try { fichero = new FileWriter("res.txt"); pw = new PrintWriter(fichero); } catch (IOException e) { } pw.println(3000); LFSR rng = new LFSR(4447); for(int i = 1; i <= 3000; i++) { double next = rng.nextDouble(); pw.println(next); } try { fichero.close(); } catch (IOException ex) { Logger.getLogger(LFSR.class.getName()).log(Level.SEVERE, null, ex); } } }
On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote:

> On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: >> hi please help me to programmed linear feedback shift register >> algorithm in java > > i have this code:
<<code snipped>> So, you have code -- what's the problem? -- Tim Wescott Wescott Design Services http://www.wescottdesign.com I'm looking for work -- see my website!
On 1.4.17 20:44, Tim Wescott wrote:
> On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote: > >> On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: >>> hi please help me to programmed linear feedback shift register >>> algorithm in java >> >> i have this code: > > <<code snipped>> > > So, you have code -- what's the problem? >
There is a strong smell of a homework deadline. -- -TV
On Saturday, April 1, 2017 at 8:44:45 PM UTC+3, Tim Wescott wrote:
> On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote: > > > On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: > >> hi please help me to programmed linear feedback shift register > >> algorithm in java > > > > i have this code: > > <<code snipped>> > > So, you have code -- what's the problem? > > -- > > Tim Wescott > Wescott Design Services > http://www.wescottdesign.com > > I'm looking for work -- see my website!
this code doesn't work correctly
On Saturday, April 1, 2017 at 9:39:17 PM UTC+3, Tauno Voipio wrote:
> On 1.4.17 20:44, Tim Wescott wrote: > > On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote: > > > >> On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: > >>> hi please help me to programmed linear feedback shift register > >>> algorithm in java > >> > >> i have this code: > > > > <<code snipped>> > > > > So, you have code -- what's the problem? > > > > There is a strong smell of a homework deadline. > > -- > > -TV
sorry , what did you mean ?
On Saturday, April 1, 2017 at 8:44:45 PM UTC+3, Tim Wescott wrote:
> On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote: > > > On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: > >> hi please help me to programmed linear feedback shift register > >> algorithm in java > > > > i have this code: > > <<code snipped>> > > So, you have code -- what's the problem? > > -- > > Tim Wescott > Wescott Design Services > http://www.wescottdesign.com > > I'm looking for work -- see my website!
excuse me , how to contact wescott design ?
On Sat, 01 Apr 2017 13:12:50 -0700, dahawi amer wrote:

> On Saturday, April 1, 2017 at 9:39:17 PM UTC+3, Tauno Voipio wrote: >> On 1.4.17 20:44, Tim Wescott wrote: >> > On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote: >> > >> >> On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: >> >>> hi please help me to programmed linear feedback shift register >> >>> algorithm in java >> >> >> >> i have this code: >> > >> > <<code snipped>> >> > >> > So, you have code -- what's the problem? >> > >> > >> There is a strong smell of a homework deadline. >> >> -- >> >> -TV > sorry , what did you mean ?
"Please send me completed work". And, it's Finals Week. With apologies if that's not the case, but this is more a group to ask "how do I do this" or "how do I find this", rather than "send me this now, chop chop!!" -- Tim Wescott Control systems, embedded software and circuit design I'm looking for work! See my website if you're interested http://www.wescottdesign.com
On Sat, 01 Apr 2017 13:14:50 -0700, dahawi amer wrote:

> On Saturday, April 1, 2017 at 8:44:45 PM UTC+3, Tim Wescott wrote: >> On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote: >> >> > On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: >> >> hi please help me to programmed linear feedback shift register >> >> algorithm in java >> > >> > i have this code: >> >> <<code snipped>> >> >> So, you have code -- what's the problem? >> >> -- >> >> Tim Wescott Wescott Design Services http://www.wescottdesign.com >> >> I'm looking for work -- see my website! > excuse me , how to contact wescott design ?
See my website. There's contact information there. -- Tim Wescott Control systems, embedded software and circuit design I'm looking for work! See my website if you're interested http://www.wescottdesign.com
On Sat, 01 Apr 2017 13:11:25 -0700, dahawi amer wrote:

> On Saturday, April 1, 2017 at 8:44:45 PM UTC+3, Tim Wescott wrote: >> On Sat, 01 Apr 2017 04:55:55 -0700, dahawi amer wrote: >> >> > On Saturday, April 1, 2017 at 2:27:49 PM UTC+3, dahawi amer wrote: >> >> hi please help me to programmed linear feedback shift register >> >> algorithm in java >> > >> > i have this code: >> >> <<code snipped>> >> >> So, you have code -- what's the problem? >> >> -- >> >> Tim Wescott Wescott Design Services http://www.wescottdesign.com >> >> I'm looking for work -- see my website! > > this code doesn't work correctly
We might be able to help you more if you let us know what you're trying to achieve, and how the code isn't working correctly (or how you know it's not working correctly). It will also help if you let us know if you wrote the code, and if so, what book or paper you're working off of (particularly if you can point to a link). If you didn't write the code, letting us know (again, preferably, with a link) where it came from will help. Scanning the code it looked like generic LFSR code, but completely unoptimized for speed. I didn't look at it in great detail, though -- a few people on these groups will, but most don't want to take that much time. -- Tim Wescott Control systems, embedded software and circuit design I'm looking for work! See my website if you're interested http://www.wescottdesign.com