| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 
 | #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
 
int randomNoDouble(int min, int max, long *tableau, long sizeTableau, int i);
int random(const int MIN, const int MAX);
 
int TablAlea(int i; int j)
{
        srand(time(NULL));
        long size = 5;
        long *tab = NULL;
        int min = i, max = j;
 
        tab = new long[size];
        for (int i=0;i<5;i++) {
                tab[i] = -1;
// j'initialise les valeurs de ton tableau à des valeurs qu'il ne devrait pas contenir
        }
 
        for(int i = 0 ; i < 5 ; i++)
        {
                cout<<randomNoDouble(min,max,tab,size,i)<<endl;
        }
 
        delete[] tab;
 
        return 0;
}
 
int randomNoDouble(int min, int max, long *tableau, long sizeTableau, int i)
{
        bool ok;
 
        do // plus pratique parce qu'on test au moins une fois
        {
                tableau[i] = random(min,max);
                ok = false;
                if(i>0)
                {
// condition de sortie : tant qu'il es tdifférent de -1 parce que ça sert à rien de tester plus loin
                        for(int j=0; j<sizeTableau && tableau[j] != -1;j++)
                        {
// Si tu dis pas que j est différent de i alors tu tourneras en rond pendant des heures
// Il testera la même valeur en permanence.
                                if(i != j && tableau[i] == tableau[j])
                                {
// on continue la boucle si on trouve 2 valeurs identiques.
                                        ok = true;                                }
                        }
                }
        }while(ok);
 
        return tableau[i];
}
 
int random(const int MIN, const int MAX)
{
        int random;
        return random = (rand() % (MAX - MIN + 1)) + MIN;
} | 
Partager