1. fifo
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Rep Power

    Frequency of random numbers

    I am needing to calculate, first the mean of 1000 random numbers, which i have done (see below code) and then the frequency of each number as a percentage, which i am finding very difficult. Could anyone point me in the right direction?

    #include <stdio.h>
    #include <stdlib.h>

    int main (void)
    int random_number ;
    int count, total ;
    float mean ;
    total = 0 ;

    for (count=0; count<1000; count++)
    random_number = (int) (10.0*rand()/(RAND_MAX+1));
    total += random_number; }

    mean = (float) total/1000 ;

    printf("Mean of random numbers is %f\n",mean) ;

    return 0;
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Rep Power
    I have posted several things on just such a subject, try searching the forum on 'mitakeet' and 'rand' and see what you pull up.

    And another thing, enclose your code in "code" tags!

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo