Generate a bunch of random data : Random « Math « C / ANSI-C






Generate a bunch of random data

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

const int MAX = 40;
int main()
{
    int index;

    for (index = 0; index < 20; ++index) {
       int number;

       number = rand();
       printf("%d\n", (number % (MAX-1)) +1);
    }
    return (0);
}

 

           
       








Related examples in the same category

1.A random thought for the day
2.A random number is chosen between 1 and 100
3.Output random sequence
4.Work with random number
5.Seed rand() with the system time and display the first 10 numbers
6.Generate random number
7. Generate random number: how to use rand Generate random number: how to use rand
8. Initialize random number generator: how to use rand/srand
9.Output a random number