keeping stats - probability

This is a discussion on keeping stats - probability within the C++ Programming forums, part of the General Programming Boards category; How would I determine the probability of a given number occuring in the follow code? Just how bad is the ...

  1. #1
    -JM
    -JM is offline
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79

    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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    int count[20];
    ...
    count[x]++; // count how many times each x occurred...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    -JM
    -JM is offline
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    cryptographically secure PRNG
    I don't know what this means - you keep your pants on while solving crossword puzzles??

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #7
    -JM
    -JM is offline
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to build a baseball stats database
    By Programmer3922 in forum C Programming
    Replies: 1
    Last Post: 08-02-2008, 12:01 AM
  2. Whoa... tough one here.
    By nickodonnell in forum Game Programming
    Replies: 10
    Last Post: 10-08-2005, 01:40 PM
  3. Switching CS to Stats?
    By Extrovert in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-20-2004, 03:24 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM
  5. Old Board stats
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 08-22-2001, 12:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21