0

I am writting a program that takes in a number that ranges from 0-255 from an input file and a chip number, then I have to do a CDMA encoding on it. I am having a couple problems with the seeded random number generator. I need to have a 4 bit number generator for each bit read in and it keeps giving me problems. Below is the code that I have created. Thank you for the help.

try{
    	  inputFile = br.readLine();
          File f;
          f=new File(inputFile);
          String strLine = null;
          BufferedReader iFile = new BufferedReader (new FileReader(f));
          
          while ((strLine = iFile.readLine()) != null)   {
                  // The value taken from each line of the input file
        	  float fl = Float.valueOf(strLine.trim()).floatValue();
        	  // Converted to int so that it floors the value
        	  int i = (int)fl;
        	  String st = "";
        	  st = Integer.toBinaryString((int)i);
        	 
        	  String string = "";
        	  String bString = "";
        	  System.out.println("st = " + st);
        	  // Reads each bit 
        	  for (int q = 0; q < st.length(); q++){
        		  char cd = st.charAt(q);
        		  
        		  string = String.valueOf(cd);
        		  int c = Integer.parseInt(string);
        		  l = Long.parseLong(seed.trim());
        		
        		  // Inverts the chip number if the input bit is 0
        		  if (cd == '1'){
        			  bString = bString + chipNumber;
        		  }
        		  if (cd == '0'){
        			  bString = bString + chipInverse;
        		  }
        		  
        		  //declare a new instance of the Random class
                         
        		  	Random aRandom = new Random();
        		  	aRandom.setSeed(l);
        		   
        		    
        		  
        		    int out = aRandom.nextInt(c);
        		     
        		    String outString = Integer.toBinaryString((int) out);
        		    String finalString = "";
        		    finalString = finalString + outString;
        		    
        	}
        		  
        	  }
       } catch (IOException ioe) {
          System.out.println("IO error trying to read input file");
          System.exit(1);
       }
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by brianlevine
0

It's been a while since I used java random number generator, so hopefully someone will correct me if I'm wrong, but I believe if you use the same seed for the Random number generator you'll get the same output each time. Is this what you want?

What's the problem you're seeing?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.