Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

About random number in C

  1. Dec 25, 2005 #1
    i generate a sequence of random number in [0,9], and i need to know whether the random number is uniform or not, so i should check how many
    time of 1 or 2 or 3....had been generated by the generator???
    but my program is not work!!???

    void main()
    char fname[]="SRN.txt";
    int i,j,y,a[100];
    srand (time(NULL));

    and how can i create a uniform ramdom number generator
  2. jcsd
  3. Dec 25, 2005 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I don't think your problem is with C; I'm not entirely sure you know exactly what you're trying to do!

    Try writing out in words what you are trying to do. Your goal is to write directions that are detailed enough that someone who has absolutely no idea what you're trying to do can follow the instructions.
  4. Dec 25, 2005 #3
    if y is your random numbe ryou reset it everytime...that will probably be your problem. Actually its problably the problem anyways. There are several books out there for random generators, pick up sedgewick's text. I'm sure you can find a standard random generator formula...www.mathworld.com
  5. Dec 26, 2005 #4
    int j;
    int k;
    int array[10]={0};
    printf(" enter size");
    scanf("%d", size);
    for( i=0; i< size; i++);
    j=rand( )% 10; /*there is got to be something more*/
  6. Dec 26, 2005 #5
    Thank you very much....
    i know my ramdon generator is bad~~
    i will find on some place...:smile:
  7. Dec 28, 2005 #6

    jim mcnamara

    User Avatar

    Staff: Mentor

    This article uses a tiny amount of math but is very clearly written:

    http://www.eternallyconfuzzled.com/articles/rand.html [Broken]
    Last edited by a moderator: May 2, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook