1. 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.

2. 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

3. 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 "pseudo-random" number divisible by 10 (or seen in a diffrent way, that ends with 0). In other words, the resulting "pseudo-random" number will always be a multiple of the prime factors of the constant.

A way around this would be to multiply 2 pseudo-random 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

4. Here is the completed program. You'll need to run it in a dos window.

5. 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;

}

6. just use:
"using namespace std;"
insead of having to define scope each time...

Ammo

7. 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!!

8. Haha , nice post xmaddness ... i think that yeah , i could be ??

9. 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 "pseudo-random" number divisible by 10 (or seen in a diffrent way, that ends with 0). In other words, the resulting "pseudo-random" number will always be a multiple of the prime factors of the constant.

A way around this would be to multiply 2 pseudo-random 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 ....

10. 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
•