By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,568 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,568 IT Pros & Developers. It's quick & easy.

Does hotbits hate me ... or is something else wrong here?

blazedaces
100+
P: 284
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:

Expand|Select|Wrap|Line Numbers
  1. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 256
  2.     at randomX.randomHotBits.fillBuffer(randomHotBits.java:43)
  3.     at randomX.randomHotBits.nextByte(randomHotBits.java:58)
  4.     at randomX.randomX.nextShort(randomX.java:170)
  5.     at randomX.randomX.nextInt(randomX.java:73)
  6.     at randomX.randomX.nextLong(randomX.java:80)
  7.     at randomX.randomX.nextDouble(randomX.java:94)
  8.     at MakeRandomAlphaNumerics.randomNumber(MakeRandomAlphaNumerics.java:22)
  9.     at MakeRandomAlphaNumerics.randomAlphaNumeric(MakeRandomAlphaNumerics.java:33)
  10.     at MakeRandomAlphaNumerics.main(MakeRandomAlphaNumerics.java:44)
  11.  
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:

Expand|Select|Wrap|Line Numbers
  1. package randomX;
  2.  
  3. import java.net.*;
  4. import java.io.*;
  5. import randomX.*;
  6.  
  7. /**
  8.     Implementation of a <b>randomX</b>-compliant class which obtains
  9.     genuine random data from <a href="http://www.fourmilab.ch/">John
  10.     Walker</a>'s <a href="http://www.fourmilab.ch/hotbits/">HotBits</a>
  11.     radioactive decay random sequence generator.
  12.  
  13.     <p>
  14.     Designed and implemented in July 1996 by
  15.     <a href="http://www.fourmilab.ch/">John Walker</a>.
  16. */
  17.  
  18. public class randomHotBits extends randomX {
  19.     long state;
  20.     int nuflen = 256, buflen = 0;
  21.     byte[] buffer;
  22.     int bufptr = -1;
  23.  
  24.     //  Constructors
  25.  
  26.     /** Creates a new random sequence generator.  */
  27.  
  28.     public randomHotBits() {
  29.         buffer = new byte[nuflen];
  30.     }
  31.  
  32.     /*  Private method to fill buffer from HotBits server.  */
  33.  
  34.     private void fillBuffer()
  35.         throws java.io.IOException
  36.     {
  37.         URL u = new URL("http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits?nbytes=128&fmt=bin");
  38.         InputStream s = u.openStream();
  39.         int l;
  40.  
  41.         buflen = 0;
  42.         while ((l = s.read()) != -1) {
  43.             buffer[buflen++] = (byte) l;  //Error occurs on this line, which implies s.read() is reading more then 256 times?
  44.         }
  45.         s.close();
  46.         bufptr = 0;
  47.     }
  48.  
  49.     /** Get next byte from generator.
  50.  
  51. @return the next byte from the generator.
  52.     */
  53.  
  54.     public byte nextByte()  {
  55.         try {
  56.             synchronized (buffer) {
  57.                 if (bufptr < 0 || bufptr >= buflen) {
  58.                     fillBuffer();
  59.                 }
  60.                 return buffer[bufptr++];
  61.             }
  62.         } catch (IOException e) {
  63.             throw new RuntimeException("Cannot obtain HotBits");
  64.         }
  65.     }
  66. };
  67.  
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:
Expand|Select|Wrap|Line Numbers
  1.         while ((l = s.read()) != -1) {
  2.             if (buflen >= nuflen)
  3.                 break;
  4.             buffer[buflen++] = (byte) l;
  5.         }
  6.  
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
Jun 19 '08 #1
Share this Question
Share on Google+
13 Replies


Expert 10K+
P: 11,448
Expand|Select|Wrap|Line Numbers
  1. .
  2.         int l;
  3.  
  4.         buflen = 0;
  5.         while ((l = s.read()) != -1) {
  6.             buffer[buflen++] = (byte) l;  //Error occurs on this line, which implies s.read() is reading more then 256 times?
  7.         }
  8.         s.close();
  9.         bufptr = 0;
  10.     }
  11.  
You gave the answer yourself (read your own comment). Take care of it by
checking the buflen variable in your while condition.

kind regards,

Jos
Jun 19 '08 #2

BigDaddyLH
Expert 100+
P: 1,216
Hot damn! How can I get me a radioactive decay device for my computer! And here I was, using a pseudo-random number generator like some fresh-from-out-of-town Jasper.
Jun 19 '08 #3

blazedaces
100+
P: 284
You gave the answer yourself (read your own comment). Take care of it by
checking the buflen variable in your while condition.

kind regards,

Jos
But I mentioned in my edit that I tried that didn't I? If I write an if statement that breaks out of the while loop after buflen has reached the maximum length it starts to repeat the code it produces for me...

Or was that not "checking the buflen variable"?

Just so you all know I went to random.org (an alternative to hotbits that uses the concept of "white noise" if you will to produce real random numbers) and they can produce so many random alphanumeric codes for you. So I simply copied and pasted so many to a notepad file and I'll read it from there. I'd still like to figure out how to fix this problem though...

Again, thanks for your help.

-blazed
Jun 19 '08 #4

Expert 10K+
P: 11,448
But I mentioned in my edit that I tried that didn't I? If I write an if statement that breaks out of the while loop after buflen has reached the maximum length it starts to repeat the code it produces for me...
No matter what, that stream is definitely giving you more than 256 values, too
many for your array. You have to deal with it one way or another. True random
number generators can very well generate identical values one after another;
that's what being 'random' is all about.

kind regards,

Jos
Jun 19 '08 #5

blazedaces
100+
P: 284
No matter what, that stream is definitely giving you more than 256 values, too
many for your array. You have to deal with it one way or another. True random
number generators can very well generate identical values one after another;
that's what being 'random' is all about.

kind regards,

Jos
The odds of producing the same 8 random alphanumeric characters in a row 10 times is 1/(35^8)^10 ...

I know something else must be wrong then. It's probably somewhere else, like where the program tells it to fillBuffer() again. Perhaps if they are associated and this no longer works properly it keeps using the same series of bytes every time it asks for a double? I don't know...

By the way, the program is already completed (using the alternative website). I had to learn how to write to excel files and write rtf documents to produce and organize lots of test packages... It was quite an effort, but I think I learned a lot from the experience so it was probably worth it...

Thanks again for the help. I may come back to tackling this problem, but in all honesty it may not happen today since there's other work to get done now that the test packages are all prepared (they need to be printed and all that)...

Thanks again for your helpful input,
-blazed
Jun 19 '08 #6

Expert 10K+
P: 11,448
ps. I tried that http address (http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits?
nbytes=128&fmt=bin) and it gave me 128 bytes for a little test I ran 10,000
times. I did the same with nbytes=256 also 10,000 times and all went fine too.

kind regards,

Jos
Jun 19 '08 #7

blazedaces
100+
P: 284
ps. I tried that http address (http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits?
nbytes=128&fmt=bin) and it gave me 128 bytes for a little test I ran 10,000
times. I did the same with nbytes=256 also 10,000 times and all went fine too.

kind regards,

Jos
Then... what did I do wrong?

*sigh*

I'm confused. I'll look at this again later... Thanks again for your help and effort.

-blazed
Jun 19 '08 #8

Expert 10K+
P: 11,448
Then... what did I do wrong?
The only thing I can find now is that you're asking for 128 bytes from that server
while the rest of your code anticipates for 256 bytes ...

kind regards,

Jos
Jun 19 '08 #9

blazedaces
100+
P: 284
The only thing I can find now is that you're asking for 128 bytes from that server
while the rest of your code anticipates for 256 bytes ...

kind regards,

Jos
How am I asking for only 128 bytes? I don't even see 128 being written down as a number in the program...

Thanks,

-blazed
Jun 19 '08 #10

Expert 10K+
P: 11,448
How am I asking for only 128 bytes? I don't even see 128 being written down as a number in the program...

Thanks,

-blazed
It's in your url fragment "nbytes=128". Try "fmt=ascii" instead of "fmt=bin" as
the last fragment value so you can see what comes in using your browser.

kind regards,

Jos
Jun 19 '08 #11

Expert 10K+
P: 11,448
A little update: that server doesn't want you to request too many bytes; I looked at
what I got in and it happened to be this after a couple of requests:

< h t m l > \n < h e a d > \n < t i t l e > H o t B i t s E r r o r < g t i t l e > \n < g h e a d > \n < b o d y > \n < h 1 > E r r o r G e n e r a t i n g H o t B i t s < h 1 > \n < h r > \n < p > \n T h e f o l l o w i n g e r r o r : \n < p > \n < b l o c k q u o t e > \n < b > Y o u h a v e e x c e e d e d y o u r 2 4 - h o u r q u o t a f o r H o t B i t s . < / b > \n < / b l o c k q u o t e > \n < p > \n o c c u r r e d w h i l e p r o c e s s i n g y o u r H o t B i t s r e q u e s t . T h e s e r v e r m a y b e \n t e m p o r a r i l y d o w n ; p l e a s e t r y a g a i n i n a f e w h o u r s . \n < p > \n < h 2 > < a h r e f = " / h o t b i t s / " " > B a c k t o H o t B i t s < / a > < / h 2 > \n < / b o d y > \n < / h t m l > \n

I think this basically implies that the server wants to protect itself from DOS attacks.
It's a bit strange that I didn't see this yesterday ...

kind regards,

Jos
Jun 20 '08 #12

blazedaces
100+
P: 284
A little update: that server doesn't want you to request too many bytes; I looked at
what I got in and it happened to be this after a couple of requests:

< h t m l > \n < h e a d > \n < t i t l e > H o t B i t s E r r o r < g t i t l e > \n < g h e a d > \n < b o d y > \n < h 1 > E r r o r G e n e r a t i n g H o t B i t s < h 1 > \n < h r > \n < p > \n T h e f o l l o w i n g e r r o r : \n < p > \n < b l o c k q u o t e > \n < b > Y o u h a v e e x c e e d e d y o u r 2 4 - h o u r q u o t a f o r H o t B i t s . < / b > \n < / b l o c k q u o t e > \n < p > \n o c c u r r e d w h i l e p r o c e s s i n g y o u r H o t B i t s r e q u e s t . T h e s e r v e r m a y b e \n t e m p o r a r i l y d o w n ; p l e a s e t r y a g a i n i n a f e w h o u r s . \n < p > \n < h 2 > < a h r e f = " / h o t b i t s / " " > B a c k t o H o t B i t s < / a > < / h 2 > \n < / b o d y > \n < / h t m l > \n

I think this basically implies that the server wants to protect itself from DOS attacks.
It's a bit strange that I didn't see this yesterday ...

kind regards,

Jos
Well... it's good to know what the problem may have been. Thank you. May I ask exactly what DOS stands for in this case?

Like I said I found an alternative solution to the problem so it's all good now.

Thanks again,

-blazed
Jun 21 '08 #13

Expert 10K+
P: 11,448
Well... it's good to know what the problem may have been. Thank you. May I ask exactly what DOS stands for in this case?

Like I said I found an alternative solution to the problem so it's all good now.

Thanks again,

-blazed
DOS == Denial Of Service attack: by burrying the server under your requests
it can't find any time/resources to service anything else.

kind regards,

Jos
Jun 21 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.