473,469 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

blazedaces
284 Contributor
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
13 2556
JosAH
11,448 Recognized Expert MVP
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
1,216 Recognized Expert Top Contributor
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
284 Contributor
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
JosAH
11,448 Recognized Expert MVP
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
284 Contributor
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
JosAH
11,448 Recognized Expert MVP
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
284 Contributor
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
JosAH
11,448 Recognized Expert MVP
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
284 Contributor
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
JosAH
11,448 Recognized Expert MVP
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
JosAH
11,448 Recognized Expert MVP
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
284 Contributor
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
JosAH
11,448 Recognized Expert MVP
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

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

Similar topics

30
by: Christian Seberino | last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python? Python's design is godly. I'm wondering if Ruby's is godly too. I've heard it has solid OOP design but then...
5
by: Jeremy | last post by:
I have a very large HTML form (with about 50 fields) that's being submitted to an ASP page via the "POST" method. I don't use "GET" because the data would probably exceed the limit allowed in the...
44
by: Bamber | last post by:
Why does f get returned ? (compiled with gcc). #include<stdio.h> int func(int a); main() { int f; f=func(7); printf("f=%d",f);
29
by: SysSpider | last post by:
Hi again, This is my problem: when i try to compile the code that contains the function below, i get this: -- gcc:21: error: case label does not reduce to an integer constant gcc:24: error:...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
17
by: Barret Bonden | last post by:
As an old programmer just now looking at VB.net I have a question: How does one simply open one form from another ? I don't mean how does one create a new instance of that form , but rather how...
40
by: PJ6 | last post by:
I want to rant, but I'm too busy at the moment. Who else hates working in C#? What's your biggest pet peeve? Paul
15
by: Jon Davis | last post by:
Bill Wagner posted something here .. http://msdn2.microsoft.com/en-us/vcsharp/default.aspx "Local Type Inference, Anonymous Types, and var" "Of all the features in C# 3.0, local type inference...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.