Since I needed many codes I ran the program last night and then all of a sudden it spit out the following error:
Expand|Select|Wrap|Line Numbers
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 256
- at randomX.randomHotBits.fillBuffer(randomHotBits.java:43)
- at randomX.randomHotBits.nextByte(randomHotBits.java:58)
- at randomX.randomX.nextShort(randomX.java:170)
- at randomX.randomX.nextInt(randomX.java:73)
- at randomX.randomX.nextLong(randomX.java:80)
- at randomX.randomX.nextDouble(randomX.java:94)
- at MakeRandomAlphaNumerics.randomNumber(MakeRandomAlphaNumerics.java:22)
- at MakeRandomAlphaNumerics.randomAlphaNumeric(MakeRandomAlphaNumerics.java:33)
- at MakeRandomAlphaNumerics.main(MakeRandomAlphaNumerics.java:44)
Now, I'm going to post the code for the program where the error finally occurs (in the method fillBuffer()). See, the funny thing is, this error occurred only after the percentage out of 3217 random codes was about .01 (my calculation of this number could possibly be wrong I guess) which amounts to only approximately 32 codes, but I've ran this program previously to produce a hundred alphanumeric codes to test it out when I needed to produce some demo sheets for approval.
My question is should this be happening? Is this indeed some kind of security measure taken by the website? If so, can I get thousands of codes somehow from this same source by simply setting up my program to take so many codes, then wait (using a timer perhaps) and then take more (maybe you can give me an alternative solution)?
Here's the codes for the randomX.hotBits program and I've marked where the error occurs:
Expand|Select|Wrap|Line Numbers
- package randomX;
- import java.net.*;
- import java.io.*;
- import randomX.*;
- /**
- Implementation of a <b>randomX</b>-compliant class which obtains
- genuine random data from <a href="http://www.fourmilab.ch/">John
- Walker</a>'s <a href="http://www.fourmilab.ch/hotbits/">HotBits</a>
- radioactive decay random sequence generator.
- <p>
- Designed and implemented in July 1996 by
- <a href="http://www.fourmilab.ch/">John Walker</a>.
- */
- public class randomHotBits extends randomX {
- long state;
- int nuflen = 256, buflen = 0;
- byte[] buffer;
- int bufptr = -1;
- // Constructors
- /** Creates a new random sequence generator. */
- public randomHotBits() {
- buffer = new byte[nuflen];
- }
- /* Private method to fill buffer from HotBits server. */
- private void fillBuffer()
- throws java.io.IOException
- {
- URL u = new URL("http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits?nbytes=128&fmt=bin");
- InputStream s = u.openStream();
- int l;
- buflen = 0;
- while ((l = s.read()) != -1) {
- buffer[buflen++] = (byte) l; //Error occurs on this line, which implies s.read() is reading more then 256 times?
- }
- s.close();
- bufptr = 0;
- }
- /** Get next byte from generator.
- @return the next byte from the generator.
- */
- public byte nextByte() {
- try {
- synchronized (buffer) {
- if (bufptr < 0 || bufptr >= buflen) {
- fillBuffer();
- }
- return buffer[bufptr++];
- }
- } catch (IOException e) {
- throw new RuntimeException("Cannot obtain HotBits");
- }
- }
- };
Expand|Select|Wrap|Line Numbers
- while ((l = s.read()) != -1) {
- if (buflen >= nuflen)
- break;
- buffer[buflen++] = (byte) l;
- }
Don't know if that information helped you guys at all.
Thank you for all and any of your help,
-blazed