English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C Standard Library - <stdlib.h>
Fonction de bibliothèque C int rand(void) Renvoie une valeur comprise entre 0 et RAND_MAX entre des nombres pseudo-aléatoires.
RAND_MAX est une constante whose default value may vary between implementations, but its value is at least 32767.
Voici la déclaration de la fonction rand().
int rand(void)
Cette fonction renvoie une valeur entière comprise entre 0 et RAND_MAX.
Le présent exemple montre l'utilisation de la fonction rand().
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int i, n; time_t t; n = 5; /* Initialiser le générateur de nombres aléatoires */ srand((unsigned) time(&t)); /* Output 0 to 49 between 5 A random number */ for( i = 0 ; i < n ; i++ ) { printf("%d\n", rand() % 50); {} return(0); {}
Let's compile and run the above program, which will produce the following results:
38 45 29 29 47