# keeping stats - probability

• 08-20-2005
-JM
keeping stats - probability
How would I determine the probability of a given number occuring in the follow code? Just how bad is the infamous rand()?
Code:

```#include<iostream> #include<ctime> int main() {         srand(time(0));         int testCases = 100;         for(int i = 1; i <= testCases; i++)         {           int x = rand()%20+1;           std::cout<<x<<'\t';}         std::cin.get();         return 0; }```
I need another test loop and 20 variables to increment(?). I'm a little over my head on this.

Thanks -

JM
• 08-20-2005
Salem
int count[20];
...
count[x]++; // count how many times each x occurred...
• 08-20-2005
Codeplug
>> Just how bad is the infamous rand()?
gg
• 08-20-2005
Zach L.
Well, you can always run the DieHard tests.

Keep in mind, you don't necessarily need a cryptographically secure PRNG for many applications of random numbers.

Cheers
• 08-20-2005
-JM
Quote:

cryptographically secure PRNG
I don't know what this means - you keep your pants on while solving crossword puzzles?? :confused:
• 08-20-2005
Zach L.
PRNG : Pseudo-random number generator (e.g. rand)
A lot of cryptographic protocols rely on the generation of very good random numbers to keep your data secure. Because of their application, the numbers must be really "good" random numbers (cryptographically secure).
• 08-20-2005
-JM
Quote:

PRNG : Pseudo-random number generator (e.g. rand)
Cool, got it, thanks; pardon my smart-assedness!
I've done a little testing using Salem's suggestion (thanks Salem).
Rand() is good enough for the simple stuff I'm doing but thank you for all the info, I've learned a lot!

- JM