Probleme Comprehension Algorithme Aleatoire

Fermé
Tears_of_destiny Messages postés 12 Date d'inscription samedi 18 avril 2009 Statut Membre Dernière intervention 10 décembre 2010 - 22 avril 2009 à 17:49
Bonjour,

Comme dans le montre clairement le titre, g un problème a comprendre un algorithme(langage C) visant a afficher des chiffres aléatoires sans répétitions. Or, g du mal comprendre trois lignes, que voici:
#include "stdafx.h"
#include "stdlib.h"
#include "time.h"

#define DIM 10

int main(int argc, char* argv[])
{
int i,j, t[DIM+1];

t[1] = 1;
srand(unsigned(time(NULL)));

// Tirage
for ( i = 2; i <= DIM; i++ ) {
j = rand()%i+1;
t[i] = t[j];
t[j] = i;
}

// Affichage
for ( i = 1; i <= DIM; i++ )
printf("t[%d] = %d\n", i, t[i]);
return 0;
}

les trois lignes sont:
"for ( i = 2; i <= DIM; i++ ) {
j = rand()%i+1;
t[i] = t[j];
t[j] = i;
}"

Merci beaucoup de votre aide