Thread: Quantum Random Bit Generator

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    81

    Question Quantum Random Bit Generator

    I am working on a personal project which requires me to generate large amounts of truly random numbers (hint: its about probabilities).

    but as we know, rand() and srand() are only psuedo-random number generators, and poor ones at that.

    thanks to the almighty google, I was able to find a truly interesting website, which uses a piece of hardware called the Quantum Random Bit Generator. The device uses the only known source of true randomness in the universe, namely quantum uncertainty, to generate truly random bits. The website provides free C++ and DLLs which users can download and use to download data directly from the device. Needless to say, this is not only extremely cool but also VERY helpful for my project.

    However, I am getting errors when I try to compile the cpp's they provided. My debugging skills are amateur at best, so I was hoping someone on the forum would be able to help me out with this

    I will post the errors in my next post. What is the best way to post the code? Should I just attach the original cpp's and headers, or should I paste the code (its a lot ), or should I paste only those lines which are causing the errors?

    Assistance will be MUCH appreciated

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I'd just post the errors first.

    Does that site have its own support and/or forums?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The lines (a few before and after is usually very helpful) and the actual error message, including the line number (and an indication what line that is in your code).

    It is often not necessary to have ALL the source code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    81
    hi guys,

    nope, the site doesn't have it own forum/support. i think they figured that only those who could get around little bugs like these deserved to use the service . when registering (which is free), their human verification method was to actually ask the user to solve a trigonometric differential calculus problem...the first one of which I couldn't solve . The site is http://random.irb.hr/ if anyone wants to check it out. Here's the page for the device: http://qrbg.irb.hr/


    the file is example1.cpp. It uses QRBG.cpp and QRBG.h, both of which are in the same folder. im using Borland C++ on Windows XP.

    Pasted below are the errors. Immediately below each error is the line that caused it, copied and pasted directly from the code as-is.

    Code:
    - type name expected
    class InvalidArgumentError : public exception {};
    
    - type name expected
    	class NetworkSubsystemError : public exception {};	
    
    - type name expected
    	class ConnectError : public exception {};
    
    - type name expected
    class CommunicationError : public exception {};
    
    - type name expected
    class ServiceDenied : public exception { 
    
    - Declaration terminated incorrectly
    template<class _Type>
    
    - Declaration terminated incorrectly (example0.cpp (25,1) )
    The last error is perplexing. example0.cpp has only 24 lines! there is no line 25.


    Also, the 3 files are only 1K, 21K, and 13K so let me know if you want me to attach them.
    Thanks!

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It sounds like it doesn't like exception. Is <exception> #include'd in that file? Is the std namespace specified?

  6. #6
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Or it is included and all of that, but you use an old compiler. Which one are you using?

    They're using

    "#include <string.h>"
    "uint8 cbUsername = static_cast<uint8>"

    This seems a little awkward to me

    ps: thermic white noise is also purely random

  7. #7
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    Talking

    This is what I've downloaded after having found the root for 'x^2 -8x +16' = '(x-4)^2' :d

    Code:
    #pragma once
    #pragma warning( disable : 4290 )
    
    #include <stddef.h>	// size_t
    #include <exception>  // class exception
    #include <typeinfo>    // typeid
    
    using namespace std;
    
    class QRBG {
     public:
    
        class InvalidArgumentError : public exception {};
        class NetworkSubsystemError : public exception {};
        class ConnectError : public exception {};
        class CommunicationError : public exception {};
        class ServiceDenied : public exception { 
        public:
    	ServerResponseCodes ServerResponse; 
    	RefusalReasonCodes RefusalReason;
        public:
        ServiceDenied(ServerResponseCodes response, RefusalReasonCodes reason) : ServerResponse(response), RefusalReason(reason) {}		
    	const char* what() { return ServerResponseDescription[ServerResponse]; }
    	const char* cure() { return ServerResponseRemedy[ServerResponse]; }
    	const char* why() { return what(); }
        };
    
    };
    ' #pragma once ' is not supported on every platform (usually only windows). The only portable way to prevent multiple inclusions is the common '#ifndef -> #define -> #endif' construction.

    ' using namespace std ' should be avoided, but it does not cause your error (but then again, what compiler are you using?).

    ' exception' seems to be correctly included, so could you give us your exact error message?

    The exception class 'ServiceDenied : public exception' seems a little strange to me. Why define a 'what()' without a throw? But, it might be a lack of my knowledge.

    Further, it is a little strange to define the exception classes in the class 'QRBG' . I think they want to create a sort of namespace 'QRBG'.

    EDIT: and I would have made the two attributes 'ServerResponse' and 'RefusalReason' private ?

    EDIT EDIT: example1.cpp includes '#include <stdio.h>' and '#include <stdlib.h>'
    Last edited by MarkZWEERS; 05-15-2008 at 01:11 AM.

  8. #8
    Registered User
    Join Date
    May 2008
    Posts
    81
    i should mention that those errors I posted were received by running only example0.cpp. my assumption was that example0 would be enough to get random numbers. what i cant understand is why QRBG.cpp exists? I don't see it included in any file. am I missing anything?

    I am using Borland C++ 5.x on Windows XP.

    Daved -
    1) comments in QRBG.h say exception is a class, but I can't see it in any file?
    2) using namespace std gives me the error 'namespace name expected', dunno why. so I removed that line.

    Mark -
    Should I get rid of the pragma lines?
    Like I said, I only ran example0 and pasted all the errors I received exactly.
    So would example0 be enough for my purpose, which is simply to retrieve random numbers? Or do I need QRBG.cpp also?
    EDIT: Were you able to get it to work?

    p.s. - they gave you a quadratic eqn? bastards!
    pps - thermal noise is also a result of quantum uncertainty. even so, it is only approximately white.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It may well be that Borland C++ 5.x is not compatible with these examples. The examples appear to require a MS Visual Studio compiler. Not saying that it's not possible to fix the problems, but it's probably easier to download the Visual Studio Express 2008 compiler from MS.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> using namespace std gives me the error 'namespace name expected', dunno why. so I removed that line.

    Don't remove that line, just get a newer compiler. The express version of VC++ is free, as are other IDEs/compilers.

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    How much does that box cost? I looked on the site, but I didn't see any prices.

  12. #12
    Registered User
    Join Date
    May 2008
    Posts
    81
    - Daved:
    is the MS VC++ express edition good, as in not severely limited since its free?

    - cpjust:
    i don't know how much it costs, but I believe its not cheap. they wanted to have multiple devices as sources for the service, but couldn't since the cost is prohibitive. also, it was designed and build at a university so its not mass produced, which will make it expensive.

  13. #13
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    The express version just can't do MFC AFAIK. Other than that its the same as teh full version. You might have to downlaod the Windows SDK seperately though.

    Obviously srand and rand are inadequate for any scientific or engineering applications, but there are other methods of generating pseudorandom sequences that approach truly random.
    Last edited by abachler; 05-15-2008 at 10:52 AM.

  14. #14
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Should I get rid of the pragma lines?
    If you're going to use a Microsoft compiler there's no need, I don't know anything about MFC; will this compile with g++?
    For a gnu compiler you might delete the line "#pragma once" and encapsulate the code in the .h file in the #ifndef construction.

    So would example0 be enough for my purpose, which is simply to retrieve random numbers? Or do I need QRBG.cpp also?
    Well, I see that QRBG.h is included in the file example0.cpp , so it will use the code of the class QRBG.

    What I don't get, is that if you truly want a random number, you should be connected to the device? Otherwise it's really pseudo-random.. that's what the QRBG class is mainly about: it's (I think) the communication interface between the device and your computer.

  15. #15
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by MarkZWEERS View Post
    If you're going to use a Microsoft compiler there's no need, I don't know anything about MFC; will this compile with g++?
    For a gnu compiler you might delete the line "#pragma once" and encapsulate the code in the .h file in the #ifndef construction.
    You should not have to remove the #pragma lines. The whole point of #pragma is for the compiler to ignore it if it doesn't understand what it means.

    Having said that, #pragma is bad.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with random number generator
    By Niss in forum C Programming
    Replies: 6
    Last Post: 10-01-2008, 06:03 PM
  2. Replies: 1
    Last Post: 09-04-2007, 05:31 AM
  3. Random card generator
    By Loic in forum C++ Programming
    Replies: 13
    Last Post: 08-11-2007, 02:28 PM
  4. Random number generator between 0 and 1
    By Lord CyKill in forum C# Programming
    Replies: 1
    Last Post: 03-29-2007, 08:03 AM
  5. Fast normal random number generator
    By testing123 in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2006, 10:01 AM