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);
}