salut voici le programme comme je l'ai ecrit pour l#instant, et j#ai mis une boucle for englobante, hsitoire de voir 40 cas differents, mais dans tout les 40 cas la fonction rand semble me donner la meme valeur.
vous aurez pas une idée??
merci!!!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
63
64
65
66
67
68
69
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
 
#define NDOOR 3 
#define NOBJECTS 3
 
enum quizmaster {cabrio=0,cow1,cow2};
 
int myrand (void)
{
	static int first=0;
	if ( first ==0 )
	{
		srand((unsigned)time(NULL));
		first=1;
	};
	return (rand());
};
 
 
int main (void)
{
	enum quizmaster  door[NDOOR];
	enum boolean icase[NDOOR][NDOOR][NDOOR];
	int random=0;
	int i,j,k,l=0,m,t;
	for( t=0;t<=40;t++)
	{
		while ( ( random==0 )|| ( random==27) )
			random=myrand()%( (int)pow(NOBJECTS,NDOOR) ); // with this i get a number between   0 and 27
		// that tells us which case in the 3*3 table is to choose
 
		for ( i=0 ; i<NDOOR ; i++)				// the cases all door=cow or all=cabrio can not happen ( random!=(27||0)
			for ( j=0; j < NDOOR ; j++)
				for ( k=0; k< NDOOR ; k++ )
				{
					l++;
					if ( l==random )
					{
						door[0]=i;
						door[1]=j;
						door[2]=k;
						i=NDOOR;
						j=NDOOR;
						k=NDOOR;
					};
				};
		random=myrand()%2+1;
		for ( i=0;i<NDOOR;i++)		//  in order never to have two cabrio
			for ( j=NDOOR-1;j>=0;j--)
			{
				if ( i!=j)
					if ( (door[i]==0) && (door[j]==0) )
					{
						if ( random==1 )
							door[i]=cow1;
						else door[i]=cow2;
						i=NDOOR;j=0;
					}
 
			}; 
		printf(" %d-----%d    %d     %d\n",random,door[0],door[1],door[2]);
		scanf("%d",&m);
	}
	exit (0);
};