Fonction précédente Retour à HaypoCALC.com Retour au sommaire du manuel Retour au niveau supérieur Fonction suivante

Fonction Random

Définition

Random(STR type) renvoie un élément aléatoire du type défini :

Exemple

Calcul en pratique

HaypoCALC utilise la fonction rand() de la librairie standard C stdlib.h, elle se base sur le calcul modulo.

Exemple :


#define RAND_MAX 0x7fffffff

long next;

int rand()

{

  next *= 1103515245;

  next += 12345;

  return (next % ((unsigned long)RAND_MAX + 1));

}

Sous Visual C++ 6 :


#define RAND_MAX 0x7fff

long holdrand;

int rand(void)

{

  holdrand *= 214013L;

  holdrand += 2531011L;

  return ((holdrand >> 16) & 0x7fff);

}

Voir aussi

Par Victor STINNER (Haypo) - Validation XHTML 1.0 Strict, CSS