Page 1 of 1
Making a random number generator using PI (on c++)..?
Posted: Tue Jan 20, 2009 3:57 pm
by stykat
After, i got angry, as the neighbours on the 4th floor are so noisy that if my " blesings " would affect them the noise would be from their screaming, and then i realised how a big noob i am since i have a mess in my mind and im a noob at math, i try to figure out, how could i make a random number generator.
Even though, i am a newbie at C++, and at DarkBasic, still i would like to help my friend on this scientific project, so we have to make our own random PI generator.
THe thing is, i do not really know how to start, so like, in C++ and in any other programing languages, i cannot write fractions as i found at wiki.
Thats why, i would like to ask you guys, some things.
What header files to inlcure for this program, and do i really have to declare 10000 numbers, since thats how many numbers the program should generate ?
I got to think, that, ok, i will make 10000 variables for each number, but then, why use c++ since i would make the math, the program will only show the results.
SO like, how could i put one of the formulas that i found here
http://en.wikipedia.org/wiki/Software_f ... ing_.CF.80
to a C++ program ?
Do you know how could i implement them, or, a web site where i could find a source code for this?
I don't want you guys to build the code, just to explain, yeah, thats like, not math and not programing,,,is it ?
Re: Making a random number generator using PI (on c++)..?
Posted: Tue Jan 20, 2009 4:11 pm
by Ginto8
Here's a random number generator program:
Code: Select all
#include <iostream>
#include <ctime> // for rand() and srand()
#include <conio.h> // for getch()... really just because I like it better than system( "pause" )
int main()
{
int x;
srand( static_cast<unsigned>( time ( 0 ) ) ); // initialize random # generator
x = rand() % 100 + 1; // set x to a random # from 1 to 100
cout << "random number: " << x << endl;
getch(); // pause program
return 0;
}
Random number generation is included in the Standard Template Library (no need to make one yourself).
Re: Making a random number generator using PI (on c++)..?
Posted: Tue Jan 20, 2009 6:42 pm
by eatcomics
Heck I'm a noob and I recently made a dice roller in c++. Random numbers are pretty simple so if you need help on this you will definitly get it, I can post my code if you like...
Re: Making a random number generator using PI (on c++)..?
Posted: Wed Jan 21, 2009 4:15 pm
by stykat
Ok well shoot it,, (your code).
I tried to find some sources for a pi calculator, i found some, i can poste the code if you want, however its about 2880 lines of code.
Re: Making a random number generator using PI (on c++)..?
Posted: Wed Jan 21, 2009 4:22 pm
by Ginto8
Stykat, please take a look at my previous post. rand() lets you generate a random number, though you have to use srand( [stuff] ) first. There is no need to rip your hair out trying to make one from scratch.
Re: Making a random number generator using PI (on c++)..?
Posted: Wed Jan 21, 2009 4:33 pm
by stykat
i did saw the Random number generator, but that one will generate a number between 1 and 100, as you wrote in the comment on the code what i have to make is, one, by calculating the PI, to find a bigger approximation of PI, this is for demonstrating that two things are different (i can't really say them, i don't know why), thats why i tried to search for a program that calculates the pi so i can generate random numbers.
Another thing is that, the code you used, didn't worked for me, the other that, it didn't showed anything, except, press any key to continue.
Re: Making a random number generator using PI (on c++)..?
Posted: Wed Jan 21, 2009 7:35 pm
by eatcomics
In such case my code would be of no use, seeing as how I use rand...But rand doesn't just get the numbers 1...100 it can get almost any numbers you need. But that probably doesn't matter anyways, I think your on your own for this one, we all use the rand function, I don't believe any of us make our own functions for such an operation... hmmmm if only if only.... what am I going on about???
Re: Making a random number generator using PI (on c++)..?
Posted: Wed Jan 21, 2009 7:52 pm
by MarauderIIC
stykat, firstly: is English not your first language? Either way, can you work a little harder on the punctuation and grammar? It's hard to make sense of your posts (which is probably why eatcomics is the only one really responding, he used to type like you do.)
I'm still not really sure what your objective is, or even what your real question is. Why do you need a random number generator to calculate pi? Or are you looking at generating random numbers using pi? If so, are you sure you really need to reinvent the wheel? There are built-in C++ functions to generate any random numbers you could possibly want (although as with all computer-generated random numbers, they're not totally random). If you really need to calculate pi (very hard), AND you need to calculate random numbers from it (even harder especially with a constant), I'm afraid this it out of the experience range of nearly all -- if not all -- of us, at least without research. Are you trying to show that the same seed generates the same random number, but two different seeds generate two different random numbers? If so, the built-in C++ functions should handle it fine.
Re: Making a random number generator using PI (on c++)..?
Posted: Thu Jan 22, 2009 5:21 am
by stykat
First of all,i am sorry for my bad grammar. I am Romanian and live in Romania wich is in Eastern Europe, and English is not my first language, it is the second, then the third is Hungarian.
I was trying to generate random numbers using PI, as i saw, there are some programs like Pifast and QuickPi.
What i would have to do this to "Study to demonstrate a chiral pair will produce a different statistical oucome than an achiral pair"
This is actually for a friend.
HE gave me an example with a dice, however it was not clear, then he gave me a web site for with a bunch of formulas (i posted its link).
I told him that, there are alot of Random nuber generators using pi, but, he cannot use an already made program for that.
Ok well, thank you all for making me understand some things, and thank you for your help and for the code you posted.
I will, i will try to improve my engilsh grammar.
Re: Making a random number generator using PI (on c++)..?
Posted: Fri Jan 23, 2009 9:19 pm
by eatcomics
Don't worry he was mostly trying to bring up my horribe past, which he has been doing a lot lately
And I'm glad you could find some answers to your questions
Re: Making a random number generator using PI (on c++)..?
Posted: Sat Jan 24, 2009 2:33 am
by MarauderIIC
stykat wrote:I will, i will try to improve my engilsh grammar.
I was really just trying to say that your post was difficult to read. Don't strain yourself too much. I get people around here who have english as their first language and are like
"so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much" And to simulate the effect that has if a whole post is typed like that:
so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much so...wat r u doing today i am dong gr8 can u halp me...plas thx u very much
You can see how it's hard to read just because the lack of capitalization and actual punctuation makes it hard for the eye to process. No big deal, though, if English isn't your first language you won't be held to as high standards as I try to hold the rest of these guys to :D