Hey guys, how's it going today? So basically I have a program that uses hotbits (a real online random number generator based off radioactive decay) to produce truly random alphanumeric codes (Note: the program is the package randomX from their website).
Since I needed many codes I ran the program last night and then all of a sudden it spit out the following error:
Note: this error was recorded when I ran the program to get just 10 random codes and it didn't spit one out. So another words, since I ran the program to get thousands, it has been producing this error. So my suspicion is that the website/program has been written with a defense mechanism against someone requesting too much data too many times in a row (does this make any sense at all?).
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:
[code=java]
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.c h/">John
Walker</a>'s <a href="http://www.fourmilab.c h/hotbits/">HotBits</a>
radioactive decay random sequence generator.
<p>
Designed and implemented in July 1996 by
<a href="http://www.fourmilab.c h/">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.IOExcep tion
{
URL u = new URL("http://www.fourmilab.c h/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 RuntimeExceptio n("Cannot obtain HotBits");
}
}
};
[/code]
Edit: One solution I did try earlier was to change the inside of the while loop to break if it read more than 256 times (did not work), so the while loop looked like this:
[code=java]
while ((l = s.read()) != -1) {
if (buflen >= nuflen)
break;
buffer[buflen++] = (byte) l;
}
[/code]
But that did not work. It was a bit odd. It would produce a few alphanumeric codes that were unique (about 3) and then spit out like 7 that were the same. Which seems a little odd to me, because that would mean it's repeating itself not in every 256 bytes, but rather in every 8 double's I request from it (to produce an alphanumeric random letter/number I multiply random.double() , not random from java, but random from the hotbits package, by 35 and then get either a number or a letter depending on the produced and then afterwards rounded number.
Don't know if that information helped you guys at all.
Thank you for all and any of your help,
-blazed
Since I needed many codes I ran the program last night and then all of a sudden it spit out the following error:
Code:
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:
[code=java]
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.c h/">John
Walker</a>'s <a href="http://www.fourmilab.c h/hotbits/">HotBits</a>
radioactive decay random sequence generator.
<p>
Designed and implemented in July 1996 by
<a href="http://www.fourmilab.c h/">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.IOExcep tion
{
URL u = new URL("http://www.fourmilab.c h/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 RuntimeExceptio n("Cannot obtain HotBits");
}
}
};
[/code]
Edit: One solution I did try earlier was to change the inside of the while loop to break if it read more than 256 times (did not work), so the while loop looked like this:
[code=java]
while ((l = s.read()) != -1) {
if (buflen >= nuflen)
break;
buffer[buflen++] = (byte) l;
}
[/code]
But that did not work. It was a bit odd. It would produce a few alphanumeric codes that were unique (about 3) and then spit out like 7 that were the same. Which seems a little odd to me, because that would mean it's repeating itself not in every 256 bytes, but rather in every 8 double's I request from it (to produce an alphanumeric random letter/number I multiply random.double() , not random from java, but random from the hotbits package, by 35 and then get either a number or a letter depending on the produced and then afterwards rounded number.
Don't know if that information helped you guys at all.
Thank you for all and any of your help,
-blazed
Comment