| | |
Random Number Generator Question
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 |
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth capture chat chatprogramusingobjects class classes client code color component count database derby design eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie object os print printing problem producer program programming project projectideas read recursion reference replaysolutions ria scanner screen server set size sms sort sourcelabs sql stop string swing threads transforms tree ui unicode validation windows





