
November 15th, 2002, 11:10 AM
#11
Member
Erm. The thought did cross my mind, but I managed to discard it. But yeah, please tell me this isn't for a Credit Card generator, because that would suck.
mathgirl, I didn't add any libraries, because my code wasn't really a complete working program. Twas just a snippet of the loop to generate the number.
Cheers.
I blame you cos my mind is not my own, so don't blame me if I trespass in your zone!

November 15th, 2002, 01:33 PM
#12
Senior Member
I would like to Thank all of You to help me out,
Let me take this oppourtinity to inform you that you should be rest assured that this C program is not being used for any credit cards number, or any oter antisocial activity.
As a matter of fact, i donot have the credit card and i do not even know hoemany digit number is there on the credit card.
once again THANX
U get What U pay for.

November 15th, 2002, 02:47 PM
#13
Originally posted here by RejectKnowledge
Umm, specificly 16 digits. Lets see:
In C/C++, you can use the rand() or the srand() functions. They won't give you 16 digit random numbers, you'll have to give it any algorithm you like.. for example:
randomnumber1 = srand() * 91234567890;
randomnumber2 = srand() * 99234567890
Basically, all you're doing here is generating a random number, using the 'srand()' function, and then multiplying it with a sufficiently large number. The number, ofcourse, could be anything at all. Just make sure its big. Real big.
Unfortunately, this solution isn't statistically viable:
Multiplying with a constant will limit the range of possible result; for example using 91234567890 or 99234567890 means you will always get a "pseudorandom" number divisible by 10 (or seen in a diffrent way, that ends with 0). In other words, the resulting "pseudorandom" number will always be a multiple of the prime factors of the constant.
A way around this would be to multiply 2 pseudorandom numbers together. This would already be better although I beleive that would also be statistically biased:
Half natural numbers are odd, half are even.
When multiplicating, the only way to obtain an odd number is to multiply two odd numbers.
So, the odds of obtaining an odd number when multipling two random numbers (each with 50% chance of returning an odd number) would yeild only a 25% chance, while it should be 50%...
This might not mean much at first look, but it can be crucial when carefully observed: just take a look at TCP ISN (Initial Sequence Number) prediction for example:
http://razor.bindview.com/publish/papers/tcpseq.html
http://lcamtuf.coredump.cx/newtcp/
Ammo
Credit travels up, blame travels down  The Boss

November 15th, 2002, 11:01 PM
#14
Here is the completed program. You'll need to run it in a dos window.

November 16th, 2002, 04:25 AM
#15
Junior Member
And by the way, in order for it to be proper C++, the code should be:
#include<iostream>
#include<cstdlib>
int main()
{
int a, b, cC, d, e, f, g, h, i, j, k, l, m, n, o, p, x;
std::cout<<"How many outputs would you like?"<<std::endl;
std::cin>>x;
a = 1 + rand() % 9;
b = 1 + rand() % 9;
cC = 1 + rand() % 9;
d = 1 + rand() % 9;
e = 1 + rand() % 9;
f = 1 + rand() % 9;
g = 1 + rand() % 9;
h = 1 + rand() % 9;
i = 1 + rand() % 9;
j = 1 + rand() % 9;
k = 1 + rand() % 9;
l = 1 + rand() % 9;
m = 1 + rand() % 9;
n = 1 + rand() % 9;
o = 1 + rand() % 9;
p = 1 + rand() % 9;
for(int c = 0; c <= x; c++)
std::cout<<a<<b<<cC<<d<<e<<f<<g<h<<i<<j<<k<<l<<m<<n<<o<<p<<std::endl;
return 0;
}

November 16th, 2002, 05:16 AM
#16
just use:
"using namespace std;"
insead of having to define scope each time...
Ammo
Credit travels up, blame travels down  The Boss

November 22nd, 2002, 04:40 AM
#17
Junior Member
The best way is to use the srand() method in main, but initialize it with the time:
srand(time(0)). It will use current time to randomize the use of the rand() function throughout the rest of your program. Happy coding!!

June 3rd, 2003, 10:19 PM
#18
Haha , nice post xmaddness ... i think that yeah , i could be ??

June 4th, 2003, 04:32 AM
#19
Unfortunately, this solution isn't statistically viable:
Multiplying with a constant will limit the range of possible result; for example using 91234567890 or 99234567890 means you will always get a "pseudorandom" number divisible by 10 (or seen in a diffrent way, that ends with 0). In other words, the resulting "pseudorandom" number will always be a multiple of the prime factors of the constant.
A way around this would be to multiply 2 pseudorandom numbers together. This would already be better although I beleive that would also be statistically biased:
Half natural numbers are odd, half are even.
When multiplicating, the only way to obtain an odd number is to multiply two odd numbers.
So, the odds of obtaining an odd number when multipling two random numbers (each with 50% chance of returning an odd number) would yeild only a 25% chance, while it should be 50%...
This might not mean much at first look, but it can be crucial when carefully observed: just take a look at TCP ISN (Initial Sequence Number) prediction for example:
Good point but it's also worth noting that rand and srand are both inherently *unsafe* for generating random numbers for things such as crypto keys ie. anything that you don't want someone to be able to guess. These two functions both use a very predictable method of picking a seed to generate the random number. It is better to generate random numbers using a large number of different variables that make the end result hard to guess. For example you could write a function to generate random numbers based on lots of different values that change frequently and unpredictably such as: current pid * number of currently open files * bytes memory free * thread group id ....
OpenBSD  The proactively secure operating system.

June 4th, 2003, 04:39 AM
#20
Anyone know a good website that could teach me about C++
I am very interested in it and planing to take programing next year so i just want to be ahead a bit
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

