C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-14-2008, 04:08 PM   #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
shawnt is offline   Reply With Quote
Old 05-14-2008, 04:21 PM   #2
Registered User
 
Join Date: Jan 2005
Posts: 7,137
I'd just post the errors first.

Does that site have its own support and/or forums?
Daved is offline   Reply With Quote
Old 05-14-2008, 04:23 PM   #3
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 05-14-2008, 08:13 PM   #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!
shawnt is offline   Reply With Quote
Old 05-14-2008, 08:28 PM   #5
Registered User
 
Join Date: Jan 2005
Posts: 7,137
It sounds like it doesn't like exception. Is <exception> #include'd in that file? Is the std namespace specified?
Daved is offline   Reply With Quote
Old 05-15-2008, 12:43 AM   #6
Registered User
 
Join Date: May 2008
Location: Paris
Posts: 236
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
MarkZWEERS is offline   Reply With Quote
Old 05-15-2008, 12:59 AM   #7
Registered User
 
Join Date: May 2008
Location: Paris
Posts: 236
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>'
Attached Files
File Type: h QRBG.h (900 Bytes, 37 views)
File Type: cpp QRBG.cpp (20.8 KB, 53 views)
File Type: cpp example0.cpp (863 Bytes, 40 views)
File Type: cpp example1.cpp (2.0 KB, 40 views)

Last edited by MarkZWEERS; 05-15-2008 at 01:11 AM.
MarkZWEERS is offline   Reply With Quote
Old 05-15-2008, 09:38 AM   #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.
shawnt is offline   Reply With Quote
Old 05-15-2008, 09:43 AM   #9
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 05-15-2008, 09:56 AM   #10
Registered User
 
Join Date: Jan 2005
Posts: 7,137
>> 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.
Daved is offline   Reply With Quote
Old 05-15-2008, 10:26 AM   #11
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,120
How much does that box cost? I looked on the site, but I didn't see any prices.
cpjust is offline   Reply With Quote
Old 05-15-2008, 10:37 AM   #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.
shawnt is offline   Reply With Quote
Old 05-15-2008, 10:50 AM   #13
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
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.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 05-15-2008 at 10:52 AM.
abachler is offline   Reply With Quote
Old 05-15-2008, 11:31 AM   #14
Registered User
 
Join Date: May 2008
Location: Paris
Posts: 236
Quote:
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.

Quote:
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.
MarkZWEERS is offline   Reply With Quote
Old 05-15-2008, 11:47 AM   #15
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
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.
brewbuck is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with random number generator Niss C Programming 6 10-01-2008 06:03 PM
Miniatures/Board Game NPC Generator - how to go about it? Ardavion C Programming 1 09-04-2007 05:31 AM
Random card generator Loic C++ Programming 13 08-11-2007 02:28 PM
Random number generator between 0 and 1 Lord CyKill C# Programming 1 03-29-2007 08:03 AM
Fast normal random number generator testing123 C++ Programming 2 08-17-2006 10:01 AM


All times are GMT -6. The time now is 11:18 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22