c - How to generate without repeat value in using two random () -


i generating random nos store matrix index row , column . different row , column index nos every time not repeat. time same value generating.how rectify problem.

this written .. example

4 * 4 matrix. running loop , storing date

int i; (i=0;i<6;i++)   {    row    =     arc4random() % 4 ;   column =     arc4random() % 4;    cgfloat xoffset1 = (block.contentsize.width+350)+((block.contentsize.height-15)*column);     fireblock.position = ccp(xoffset1,row*15);    statement 1--- store column;   statement 2--- store row; } 

with 16 different combinations, i'd write of them in array, shuffle array, select array.

struct row_col_index {     int row;     int column; };  /* ... */     struct row_col_index all_combinations[4*4] = {         {0, 0}, {0, 1}, {0, 2}, {0, 3},         {1, 0}, {1, 1}, {1, 2}, {1, 3},         {2, 0}, {2, 1}, {2, 2}, {2, 3},         {3, 0}, {3, 1}, {3, 2}, {3, 3},     };      shuffle(all_combinations);     (int = 0; < 6; i++) {         row = all_combinations[i].row;         column = all_combinations[i].column;         /* ... */     } /* ... */ 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -