vendredi 10 juin 2016

Long random numbers in C

My problem is really simple (silly, maybe). I need a long random number using the C language as simple as possible. I researched through out the internet and coudn't find anything that could help me. The only thing I could find was that the rand() function cannot handle numbers bigger than 32,767.

Here is part of my code, and the long number should be between 0 and 1,000,000:

#include <stdio.h>
#include <time.h>
#include <conio.h>

#define MAX 999999

void main()
{
    int i;

    printf("\n Just a test with random numbers.");

    printf("\n ------------------------------------\n\n");

    srand(time(NULL));

    for(i = 0; i < 50; i++)
    {
        printf(" %li\n", rand() % MAX+1);
    }

    printf("\n ====================================\n");
    getch();
}

Aucun commentaire:

Enregistrer un commentaire