![]() |
|
#1
|
|||
|
|||
|
ran.h Ullong
Hi folks,
since my tutor told me to learn integration via the monte carlo method I abandonded my old task. First of all I try to understand the generation of random numbers with C++ and started reading chapter 7.1. Right from the beginning I am not familiar with the expression Code:
Ullong u,v,w; I think it is some sort of initialising the variables and I gues it is some sort of unsigned long .... something? I learnd that you can call your variables with Code:
typedef So can someone please explain this little problem to me - a C++ noob. Thanks in advance! Quantum |
|
#2
|
|||
|
|||
|
All programs based on current Numerical Recipes functions should #include <nr3.h>.
The type Ullong is defined (with typedef) in nr3.h, and is used to declare an unsigned 64-bit integer. See Footnote. So, this statement declares three unsigned 64-bit integers named u, v, and w. Regards, Dave Footnote: In <nr3.h> you see two different possibilities for the typedef. There is no 64-bit integer data type defined in the current C++ standard, and different compilers use different type names. Older Microsoft C and C++ compilers have traditionally used "unsigned __int64" for 64-bit unsigned ints. It can still used with current Microsoft compilers. GNU g++ and many other compilers define the commonly used C language 64-bit data type "unsigned long long". The name of the NR3 typedef Ullong was obviously chosen to make it easy to remember that it means unsigned long long, right? Well, maybe it wasn't "obvious" before, but now it's easy to remember, right? Bottom line: #include <nr3.h>. If you are using a different (non-Microsoft) compiler and it doesn't use "unsigned long long" for an unsigned 64-bit integer data type, then consult your compiler's documentation and make your own typedef in your working copy of <nr3.h> Last edited by davekw7x; 06-14-2010 at 08:05 PM. |
|
#3
|
|||
|
|||
|
Thank you,
I just defined them: Code:
typedef unsigned long long int Ullong; typedef double Doub; typedef unsigned int Uint; But now I ask myself: Where is my random number? After running the program there opens a windows (as usually) which only says: [Press Enter to close window]. So this tells me that the program is running successfully but again: Where is my random number? On the other hand as far as I understood it, if you want to show something on the desktop you have so write Code:
cout << "here is text\n" Code:
int x; x = 5; cout << x; // <- will show 5 on the desktop Best wishes, Quantum. |
|
#4
|
|||
|
|||
|
Why would you do that? Why don't you simply include nr3.h?
Quote:
Where is your code? How does your code generate the numbers that you, somehow, expect to see? The point is: For a reasonable expectation of meaningful help, you have to give more specific information to get specific information. In addition to posting your code, you might tell us what compiler and operating system you are using. Sometimes it makes a difference to people who would like to help. (Don't post the copyrighted stuff like ran.h or any other NR3 code; just post your main program that calls the function(s).) In the meanwhile, here is an example that uses Ran to create double precision samples between 0 and 1: Code:
//
// xran.cpp: Simple example showing generation of
// double precision uniformly distributed samples
// from Ran
//
// davekw7x
//
// If necessary, change the following to use the
// path to wherever the NR3 code is located on
// your system.
//
#include "../code/nr3.h"
#include "../code/ran.h"
int main()
{
//
// Create a Ran object with a seed that is equal to system
// time. This changes every second, so you will get
// a different sequence if you rerun the program one
// second (or more) later.
//
Ran ran(time(0));
int n;
cout << "Enter a positive integer: ";
cin >> n;
if (!cin || n <= 0) {
cout << "Invalid entry!" << endl;
exit(EXIT_FAILURE);
}
cout << endl << "Here are your " << n << " deviates:" << endl;
cout << fixed << showpoint;
for (int i = 0; i < n; i++) {
cout << " " << ran.doub() << endl;
}
cout << endl
<< "Goodbye for now." << endl;
return 0;
}
Code:
Enter a positive integer: 5 Here are your 5 deviates: 0.501215 0.174450 0.943844 0.328556 0.763123 Goodbye for now. Dave Last edited by davekw7x; 06-15-2010 at 05:36 PM. |
|
#5
|
|||
|
|||
|
Thanks,
I got it.
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|