| | |
Random Number Generator Question
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 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.
Java Syntax (Toggle Plain Text)
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); }
Last edited by Matthew85; Oct 23rd, 2008 at 10:39 pm.
![]() |
Similar Threads
- Question about Random Number Generators (C++)
- C++ Random Numbers (C++)
- help: string and random number generator Questions (C++)
- Question about card game (C++)
- C++ question and some guidance (C++)
- Selecting random word from file (C++) (C++)
- Random number generation (C)
Other Threads in the Java Forum
- Previous Thread: Another Java Problem with classes
- Next Thread: get data from HTML form
| Thread Tools | Search this Thread |
911 actionlistener addball addressbook android applet application apps array automation binary bluetooth businessintelligence button card character class client code collision component consumer crashcourse css csv database desktop eclipse ee error fractal free ftp game givemetehcodez graphics gui html image integration j2me japplet java javaarraylist javac javadoc javaee javafx javaprojects jni jpanel julia jvm linked linux loan mac method migrate mobile netbeans objects online oriented phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server service set sms software sort sql swing test textfield textfields threads time tree trolltech ubuntu update utility windows





