IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

[DEBUTANT]_ pb de randomisation


Sujet :

C

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut [DEBUTANT]_ pb de randomisation
    Bonjour !
    Dans le code ci-dessous, je génère 2 types d'essais : 70 % de PS et 30 % de stop signal...Mon problème est que ces 2 types sont écrits consécutivement dans mon fichier texte alors que je souhaiterai mixer ces 2 types de façon randomisée...Si vous pouviez éclairer ma lanterne


    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    #include <math.h>
     
    int experiment;
    int N;
    int Eccentricity;
    int subfix;
    int looptrial;
    int looptrialCTM;
    int Ntrials;
    int NtrialsCTM;
    int tnum;
    int SSD_nb;
    int SSD_times;
    int a;
    float x, y, x2, y2;
     
    int init_fix_min; // defined by the user min initial fixation time
    int init_time_fix_nb; // initial fixation time determined by the random process 
    int init_fix_max;
     
    int targ_time_fix_nb;
    int targ_fix_min;
    int targ_fix_max;
     
     
    char name[20];
    char extension[5]=".txt";
    char filename;
     
    int random_nb;
     
    main()
    {
     
          srand(time(NULL));
     
          FILE *fp;
     
          printf("This programm will generate the experimental setup \n");
          printf(" \n");
          printf(" \n");
          /* type of experiment */
     
          printf("**** Last update 23 December 2008******************************** \n");
          printf(" \n");
          printf(" \n");
     
          printf("Type of experiment 1-PS,2-AS,3-CTM,4-Memory guided: ");
          scanf("%d",&experiment);
     
          printf("Calibration name: ");
          scanf("%20s",&name);   
     
     
          strcat(name,extension);
          fp = fopen(name,"w");
     
     
          printf("Eccentricy of Target (degree):  ");
          scanf("%d",&Eccentricity);
     
          printf("Number of Target (1-8):  ");
          scanf("%d",&tnum);
     
          printf("# Number of Trials? - KEEP IN MIND: this will be adjusted depending on the conditions- \n");
          scanf("%d",&Ntrials);
     
          printf("************** Timing information ***************************************** \n");
     
     
          printf("Minimum Initial Fixation Time(0ms):  ");
          scanf("%d",&init_fix_min);
     
          printf("Maximum Initial Fixation Time(5000ms):  ");
          scanf("%d",&init_fix_max);
     
          printf("Minimum Target presentation Time(0ms):  ");
          scanf("%d",&targ_fix_min);
     
          printf("Maximum Target presentation Time 5000ms):  ");
          scanf("%d",&targ_fix_max);
     
     
          printf("**************************************************************** \n");
          printf(" \n");
          printf(" \n");
     
     
     
     
          double angle = ((360/tnum) *(3.14159 / 180));
     
     
     
    /* HERE THE PRINTING PART -IN FILE STARTS */
     
     
     
     
     
     
     
     
     
     
     
     
     
         if (experiment==3)
          {
     
                     printf("Number of Stop Signal Delay ? :  ");
          scanf("%d",&SSD_nb);
     
     
              fprintf(fp,"# SSD times (ms)\n");
               while (looptrial<SSD_nb)
               {
                                printf("Times of Stop Signal Delay (ms) ? :  ");
          scanf("%d",&SSD_times);  
     
     
          fprintf(fp,"%d \n",SSD_times);
             ++looptrial;
                     }
     
               N=3;
          fprintf(fp,"# CTM-SACC: Countermanding paradigm \n");
             fprintf(fp,"# N Visual Event \n");
          fprintf(fp,"%d \n",N);
     
          fprintf(fp,"# CTM: countermanding \n");
          fprintf(fp,"# code 4 PS normale, 3 countermanding, impair droite, pair gauche \n");
     
          fprintf(fp,"# Target eccentricity \n");
          fprintf(fp,"%d \n",Eccentricity);
     
          fprintf(fp,"# Ps: VGS cibles vertes \n");
          fprintf(fp,"# Fixation centrale = 700ms \n");
          fprintf(fp,"# Cible Laterale = 900 ms \n");
          fprintf(fp,"# Intertrial 2000-2500 ms \n");
          fprintf(fp,"# temps/duree/couleur/taille fenetre ok(1) ou erreur(2) x et y tailles wind \n");
          fprintf(fp," \n");
     
     
     
    //génération des PS
     
     
      while(looptrial<(Ntrials*0.7))
          {
          random_nb = rand() % tnum;
     
     
          fprintf(fp,"%s","4");
          fprintf(fp,"%d",Eccentricity);
          fprintf(fp,"%d",random_nb);
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s \n","0");
          fprintf(fp,"%s","0");
          fprintf(fp,"%s","      ");
     
          //rand() % (HIGH - LOW + 1) + LOW;
     
           if (random_nb==0) 
                               {
                                    x=cos(angle*0)*Eccentricity; 
                                    y=sin(angle*0)*Eccentricity;    
     
     
                                     }else
     
           if (random_nb==1)
                               {
                                    x=  cos(angle)*Eccentricity;   
                                    y= sin(angle)*Eccentricity; 
     
                                     }else
     
          if (random_nb==2) 
                               {
                                    x=cos(angle*2)*Eccentricity;   
                                    y=sin(angle*2)*Eccentricity;    
     
                                     }else
          if (random_nb==3) 
                               {
                                    x=cos(angle*3)*Eccentricity;   
                                    y=sin(angle*3)*Eccentricity;     
     
                                     }else
         if (random_nb==4) 
                               {
                                    x=cos(angle*4)*Eccentricity;  
                                    y=sin(angle*4)*Eccentricity;     
     
                                     }else
         if (random_nb==5) 
                               {
                                    x=cos(angle*5)*Eccentricity;   
                                    y=sin(angle*5)*Eccentricity;     
     
                                     }else
         if (random_nb==6) 
                               {
                                    x=cos(angle*6)*Eccentricity;  
                                    y=sin(angle*6)*Eccentricity;   
     
                                     }else
         if (random_nb==7) 
                               {
                                    x=cos(angle*7)*Eccentricity;  
                                    y=sin(angle*7)*Eccentricity;     
     
                                     }else
     
     
          //cible centrale
     
          init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
          fprintf(fp,"%d",init_time_fix_nb);
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","10"); // couleur need to be done
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","8"); // taille need to be done
                fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","1");
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","0"); 
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","0");
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s \n","0");
     
          //cible latérale
     
    fprintf(fp,"%d",init_time_fix_nb);
          fprintf(fp,"%s","    ");
     
      targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);      
    fprintf(fp,"%d",targ_time_fix_nb); 
          fprintf(fp,"%s"," ");           
          fprintf(fp,"%s","10"); // couleur need to be done
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","8"); // taille need to be done
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","1"); 
          fprintf(fp,"%s"," ");
    fprintf(fp,"%.1f",x); 
          fprintf(fp,"%s"," ");
          fprintf(fp,"%.1f",y); 
          fprintf(fp,"%s"," ");
     
    fprintf(fp,"%s","7");
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s \n","0"); 
     
     
          //error window
     
     
          fprintf(fp,"%d",init_time_fix_nb);
          fprintf(fp,"%s","    ");
     
     
    fprintf(fp,"%d",targ_time_fix_nb); 
          fprintf(fp,"%s"," ");           
          fprintf(fp,"%s","0"); // couleur need to be done
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","8"); // taille need to be done
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","2"); 
     fprintf(fp,"%s"," ");
    fprintf(fp,"%.1f",x*-1); 
          fprintf(fp,"%s"," ");
          fprintf(fp,"%.1f",y*-1); 
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s"," ");
     
    fprintf(fp,"%s","7");
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s \n","0"); 
     
      fprintf(fp," \n");
          fprintf(fp," \n");
     
     
     
     
          ++looptrial;
          }
     
     
     
     
     
     
     
     
    //génération des stops
    looptrial=0;
     
     
      while(looptrial<(Ntrials*0.3))
          {
          random_nb = rand() % tnum;
     
     
          //fprintf(fp,"# Trial INFOS \n");
     
          fprintf(fp,"%s","3");
          fprintf(fp,"%d",Eccentricity);
          fprintf(fp,"%d",random_nb);
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s \n","0");
          fprintf(fp,"%s","0");
          fprintf(fp,"%s","      ");
     
          //rand() % (HIGH - LOW + 1) + LOW;
     
           if (random_nb==0) 
                               {
                                    x=cos(angle*0)*Eccentricity; 
                                    y=sin(angle*0)*Eccentricity;    
     
     
                                     }else
     
           if (random_nb==1)
                               {
                                    x=  cos(angle)*Eccentricity;   
                                    y= sin(angle)*Eccentricity; 
     
                                     }else
     
          if (random_nb==2) 
                               {
                                    x=cos(angle*2)*Eccentricity;   
                                    y=sin(angle*2)*Eccentricity;    
     
                                     }else
          if (random_nb==3) 
                               {
                                    x=cos(angle*3)*Eccentricity;   
                                    y=sin(angle*3)*Eccentricity;     
     
                                     }else
         if (random_nb==4) 
                               {
                                    x=cos(angle*4)*Eccentricity;  
                                    y=sin(angle*4)*Eccentricity;     
     
                                     }else
         if (random_nb==5) 
                               {
                                    x=cos(angle*5)*Eccentricity;   
                                    y=sin(angle*5)*Eccentricity;     
     
                                     }else
         if (random_nb==6) 
                               {
                                    x=cos(angle*6)*Eccentricity;  
                                    y=sin(angle*6)*Eccentricity;   
     
                                     }else
         if (random_nb==7) 
                               {
                                    x=cos(angle*7)*Eccentricity;  
                                    y=sin(angle*7)*Eccentricity;     
     
                                     }else
     
     
          //cible centrale
     
          init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
          fprintf(fp,"%d",init_time_fix_nb);
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","10"); // couleur need to be done
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","8"); // taille need to be done
                fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","1");
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","0"); 
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","0");
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");  
    fprintf(fp,"%s \n","0");
     
     
          //cible latérale (=error windows)
     
     
     
     
          fprintf(fp,"%d",init_time_fix_nb);
          fprintf(fp,"%s","    ");
     
     
    fprintf(fp,"%d",targ_time_fix_nb); 
          fprintf(fp,"%s"," ");           
          fprintf(fp,"%s","0"); // couleur need to be done
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","8"); // taille need to be done
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","2"); 
     fprintf(fp,"%s"," ");
    fprintf(fp,"%.1f",x); 
          fprintf(fp,"%s"," ");
          fprintf(fp,"%.1f",y); 
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s"," ");
     
    fprintf(fp,"%s","7");
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s \n","0"); 
     
     
     
     
          //windows OK
     
    fprintf(fp,"%d",init_time_fix_nb);
          fprintf(fp,"%s","    ");
     
      targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);      
    fprintf(fp,"%d",targ_time_fix_nb); 
          fprintf(fp,"%s"," ");           
          fprintf(fp,"%s","10"); // couleur need to be done
          fprintf(fp,"%s"," ");
          fprintf(fp,"%s","8"); // taille need to be done
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","1"); 
          fprintf(fp,"%s"," ");
    fprintf(fp,"%.1f",0); 
          fprintf(fp,"%s"," ");
          fprintf(fp,"%.1f",0); 
          fprintf(fp,"%s"," ");
     
    fprintf(fp,"%s","5");
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s","5"); 
          fprintf(fp,"%s"," ");
    fprintf(fp,"%s \n","0"); 
     
     
       fprintf(fp," \n");
          fprintf(fp," \n");
     
     
     
     
     
     
     
     
     
          ++looptrial;
     
          }
          }
          fclose(fp);
     
          return 0;
     
          }

  2. #2
    Membre éprouvé Avatar de BainE
    Inscrit en
    Mai 2004
    Messages
    1 327
    Détails du profil
    Informations forums :
    Inscription : Mai 2004
    Messages : 1 327
    Par défaut
    bonjour,

    j ai corrigé pas mal de truc, mis une solution qui doit fonctionner, et mis des commentaires sur certains trucs a corriger

    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    #include <math.h>
     
    int experiment;
    int N;
    int Eccentricity;
    int subfix;
    int looptrial;
    int looptrialCTM;
    int Ntrials;
    int NtrialsCTM;
    int tnum;
    int SSD_nb;
    int SSD_times;
    int a;
    float x, y, x2, y2;
     
    int init_fix_min;
    int init_time_fix_nb;
    int init_fix_max;
     
    int targ_time_fix_nb;
    int targ_fix_min;
    int targ_fix_max;
     
     
    /* j ai augmenté la taille, on va pas faire les radins ;) */
    char name[128];
    char extension[5]=".txt";
    char filename;
     
    int random_nb;
     
    void ecrire_fct1( FILE* fp, double angle )
    {
        random_nb = rand() % tnum;
     
        fprintf(fp,"4%d%d 0 \n", Eccentricity, random_nb );
        fprintf(fp,"0%s", "      " );
     
    /* autre presentation plus lisible que la cascade de if mais on doit pouvoir faire ieux encore
       (mieurx pour plus lisible
        switch( random_nb )
        {
            case 0:
                x=cos(angle*0)*Eccentricity;
                y=sin(angle*0)*Eccentricity;
                break;
     
            case 1:
                x=  cos(angle)*Eccentricity;
                y= sin(angle)*Eccentricity;
                break;
            case 2:
                x=cos(angle*2)*Eccentricity;
                y=sin(angle*2)*Eccentricity;
                break;
     
            case 3:
                x=cos(angle*3)*Eccentricity;
                y=sin(angle*3)*Eccentricity;
                break;
     
            case 4:
                x=cos(angle*4)*Eccentricity;
                y=sin(angle*4)*Eccentricity;
                break;
     
            case 5:
                x=cos(angle*5)*Eccentricity;
                y=sin(angle*5)*Eccentricity;
                break;
     
            case 6:
                x=cos(angle*6)*Eccentricity;
                y=sin(angle*6)*Eccentricity;
                break;
     
            case 7:
                x=cos(angle*7)*Eccentricity;
                y=sin(angle*7)*Eccentricity;
                break;
            default :
                init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
                break;
        }
        */
        /* ceci doit donner le meme resultat non ? */
        if( random_nb >= 0 && random_nb <= 7 )
        {
            x=cos(angle*random_nb)*Eccentricity;
            y=sin(angle*random_nb)*Eccentricity;
        }
        else
        {
            init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
        }
     
        /* j ai regrouper un peu les printf, a verifier j ai fais ca vite */
        fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
        fprintf(fp,"%d%s",init_time_fix_nb, "    " );
     
        targ_time_fix_nb = ( rand() % ( targ_fix_max - targ_fix_min + 1 ) + targ_fix_min );
     
        fprintf(fp,"%d 10 8 1 %.lf %.lf 7 5 0 \n",targ_time_fix_nb, x, y );
        fprintf(fp,"%d%s",init_time_fix_nb, "    " );
     
        fprintf(fp,"%d 0 8 2 %.lf %.lf  7 5 0 \n \n \n",targ_time_fix_nb, x * -1, y * -1 );
    }
     
    void ecrire_fct2( FILE* fp, double angle )
    {
        random_nb = rand() % tnum;
     
        fprintf(fp,"%s","3");
        fprintf(fp,"%d",Eccentricity);
        fprintf(fp,"%d",random_nb);
        fprintf(fp,"%s"," ");
        fprintf(fp,"%s \n","0");
        fprintf(fp,"%s","0");
        fprintf(fp,"%s","      ");
     
        switch( random_nb )
        {
            case 0:
                x=cos(angle*0)*Eccentricity;
                y=sin(angle*0)*Eccentricity;
                break;
     
            case 1:
                x=  cos(angle)*Eccentricity;
                y= sin(angle)*Eccentricity;
                break;
            case 2:
                x=cos(angle*2)*Eccentricity;
                y=sin(angle*2)*Eccentricity;
                break;
     
            case 3:
                x=cos(angle*3)*Eccentricity;
                y=sin(angle*3)*Eccentricity;
                break;
     
            case 4:
                x=cos(angle*4)*Eccentricity;
                y=sin(angle*4)*Eccentricity;
                break;
     
            case 5:
                x=cos(angle*5)*Eccentricity;
                y=sin(angle*5)*Eccentricity;
                break;
     
            case 6:
                x=cos(angle*6)*Eccentricity;
                y=sin(angle*6)*Eccentricity;
                break;
     
            case 7:
                x=cos(angle*7)*Eccentricity;
                y=sin(angle*7)*Eccentricity;
                break;
            default :
                init_time_fix_nb = (rand() % (init_fix_max - init_fix_min+1) + init_fix_min);
                break;
        }
     
        fprintf(fp,"%d 10 8 1 0 0 5 5 0 \n",init_time_fix_nb);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
        fprintf(fp,"%d 0 8 0 2 %.lf %.lf  7 5 0 \n",targ_time_fix_nb, x, y);
        fprintf(fp,"%d%s",init_time_fix_nb, "    ");
     
        targ_time_fix_nb = (rand() % (targ_fix_max - targ_fix_min+1) + targ_fix_min);
     
        fprintf(fp,"%d 10 8 1 %.lf %.lf 5 5 0 \n \n \n",targ_time_fix_nb, 0., 0. );
    }
     
    /* main a 2 prototype
       int main( void ) ou
       int main( int argc, char** argv )
    */
    int main( void )
    {
        double angle = 0.;
        FILE *fp = NULL;
        int nb_pharse1_a_ecrire = 0;
        int nb_pharse2_a_ecrire = 0;
        int nb_aleatoire = 0;
     
        srand(time(NULL));
     
        printf("This programm will generate the experimental setup \n");
        printf(" \n");
        printf(" \n");
        /* type of experiment */
     
        printf("**** Last update 23 December 2008******************************** \n");
        printf(" \n");
        printf(" \n");
     
        printf("Type of experiment 1-PS,2-AS,3-CTM,4-Memory guided: ");
        scanf("%d",&experiment);
     
        printf("Calibration name (max 20 char): ");
        /* sans le "&" ca suffira par contre cette lecture est pas securisé du tout pour plusieurs raisons
           je t invite a faire une recherche sur le forum, le sujet est souvent traité et sera plus complet que ne pourrait t en dire */
        scanf("%19s", name);
     
        /* vider le buffer, si le mec rentre une chaine plus grande que 20 t aura des
           surpises a la prochaine saisie */
        while( getchar() != '\n' )
        {
        }
     
        strcat(name,extension);
        fp = fopen(name,"w");
        /* il faut tester ce retour, si on peut pas ouvrir le fichier, ca donnera un joli comportement indertermié
           qui donne souvent un beau plantage */
     
        if( fp == NULL )
        {
            fprintf( stderr, "Erreur lors de l ouverture du fichier : %s\n", name );
        }
        else
        {
            printf("Eccentricy of Target (degree):  ");
            scanf("%d",&Eccentricity);
     
            printf("Number of Target (1-8):  ");
            scanf("%d",&tnum);
     
            printf("# Number of Trials? - KEEP IN MIND: this will be adjusted depending on the conditions- \n");
            scanf("%d",&Ntrials);
     
            printf("************** Timing information ***************************************** \n");
     
            printf("Minimum Initial Fixation Time(0ms):  ");
            scanf("%d",&init_fix_min);
     
            printf("Maximum Initial Fixation Time(5000ms):  ");
            scanf("%d",&init_fix_max);
     
            printf("Minimum Target presentation Time(0ms):  ");
            scanf("%d",&targ_fix_min);
     
            printf("Maximum Target presentation Time 5000ms):  ");
            scanf("%d",&targ_fix_max);
     
            printf("**************************************************************** \n");
            printf(" \n");
            printf(" \n");
     
            angle = ((360/tnum) *(3.14159 / 180));
     
            /* HERE THE PRINTING PART -IN FILE STARTS */
     
            if (experiment==3)
            {
                printf("Number of Stop Signal Delay ? :  ");
                scanf("%d",&SSD_nb);
     
                fprintf(fp,"# SSD times (ms)\n");
     
                /* looptrial vaut combien, il est jamais initialisé, il vaut peut etre 4853483754, ss_nb non plus on dirait,
                   mais pour lui je sais pas valeur faut lui donner */
                looptrial = 0;
     
                while (looptrial<SSD_nb)
                {
                    printf("Times of Stop Signal Delay (ms) ? :  ");
                    scanf("%d",&SSD_times);
     
                    fprintf(fp,"%d \n",SSD_times);
                    ++looptrial;
                }
     
                N=3;
                fprintf(fp,"# CTM-SACC: Countermanding paradigm \n");
                fprintf(fp,"# N Visual Event \n");
                fprintf(fp,"%d \n",N);
     
                fprintf(fp,"# CTM: countermanding \n");
                fprintf(fp,"# code 4 PS normale, 3 countermanding, impair droite, pair gauche \n");
     
                fprintf(fp,"# Target eccentricity \n");
                fprintf(fp,"%d \n",Eccentricity);
     
                fprintf(fp,"# Ps: VGS cibles vertes \n");
                fprintf(fp,"# Fixation centrale = 700ms \n");
                fprintf(fp,"# Cible Laterale = 900 ms \n");
                fprintf(fp,"# Intertrial 2000-2500 ms \n");
                fprintf(fp,"# temps/duree/couleur/taille fenetre ok(1) ou erreur(2) x et y tailles wind \n");
                fprintf(fp," \n");
     
                nb_pharse1_a_ecrire = Ntrials*0.7;
                nb_pharse2_a_ecrire = Ntrials*0.3;
     
                while( nb_pharse1_a_ecrire > 0 && nb_pharse2_a_ecrire > 0 )
                {
                    nb_aleatoire = rand();
     
                    if( ( nb_aleatoire % 2 ) == 1 )
                    {
                        ecrire_fct1( fp, angle );
                        nb_pharse1_a_ecrire -= 1;
                    }
                    else
                    {
                        ecrire_fct2( fp, angle );
                        nb_pharse2_a_ecrire -= 1;
                    }
                }
     
                while( nb_pharse1_a_ecrire-- > 0 )
                {
                    ecrire_fct1( fp, angle );
                }
     
                while( nb_pharse2_a_ecrire-- > 0 )
                {
                    ecrire_fct2( fp, angle );
                }
            }
     
            fclose(fp);
        }
     
        return 0;
    }
    par contre les globales c est mal, pour plusieurs raisons, tu devrais declarer les variables dans ton main et les passer en param des fonctions quand elles en ont besoin.

    Voila, bon courage

    si t as des questions hesite pas

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut

    super pour toutes ces corrections et améliorations
    Je ne ferme pas la discussion car je pars en congés et n'aurai pas le temps de tester ça tout de suite...
    Mais encore un GROS MERCI

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut
    ok c'est vraiment parfait !
    J'ai fait un sacré bon dans la compréhension grâce à tes corrections !
    Cependant, je me pose encore une ptite question de randomisation...
    Je voulais faire un random sur les chiffres entrés dans SSD_times(cf code)...ex : l'utilisateur saisi 3 SSD : 10 20 et 30...Je veux obtenir un rand de l'un de ces 3 nombres...
    Si je fais rand () % SSD_times , cela me sort des nombres aléatoires dans la fourchette que l'utilisateur a saisi et moi je voudrai un random des nombres saisis...Si qqn a une idée...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
     
     
     
     while (looptrial<SSD_nb)
                {
                    printf("Times of Stop Signal Delay (ms) ? :  ");
                    scanf("%d",&SSD_times);
     
                    fprintf(fp,"%d \n",SSD_times);
                    ++looptrial;
                }
    Merci à tous

  5. #5
    Expert confirmé

    Inscrit en
    Août 2006
    Messages
    3 967
    Détails du profil
    Informations forums :
    Inscription : Août 2006
    Messages : 3 967
    Par défaut
    Hoe,

    Une solution, pas forcément la meilleure :

    Stocker les valeurs entrées dans un tableau, et le random te tirera l'indice à utiliser dans ce tableau.

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 138
    Par défaut
    je cloture et rouvre une autre discussion, ce problème étant résolu...
    Merci à ceux qui m'ont aidé

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [FLASH] pb debutant
    Par ultrakas dans le forum Flash
    Réponses: 2
    Dernier message: 05/06/2003, 00h48
  2. [debutant]Limiter le temps de saisi
    Par Nasky dans le forum C
    Réponses: 5
    Dernier message: 17/03/2003, 15h47
  3. [Debutant] Fichier war
    Par saispasfau dans le forum JBuilder
    Réponses: 2
    Dernier message: 17/03/2003, 15h32
  4. Réponses: 3
    Dernier message: 09/02/2003, 01h09
  5. Algorithme de randomisation ... ( Hasard ...? )
    Par Anonymous dans le forum Assembleur
    Réponses: 8
    Dernier message: 06/09/2002, 14h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo