90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

rand() % 10 + 1 should generate numbers from 1 to 10 at random so one in ten should be set to '1' the rest will be left alone. Unfortunately, because you are not clearing the array first, all the rest may be random values. If you use:

if(ran == 1)

{

m[i][j] = 1;

s = s + 1;

printf("m[%d][%d] = %d\n", i, j, m[i][j]);

}

else

{

m[i][j] = 0;

}

you will get a more reliable result.

>>and now i want that i can set M m[x][y] = 1(= i want to generate M points that mark with "1", but must place random within the 100 x 100) as i want, like below?

If this means what I think it means then perhaps:

>> while(s < M)

should become

if(s < M)

but this would only fill the first ten that would normall be set.

If you really want ten random entries set to '1' then use something like:

// Clear the array.

for(i = 0; i < X; i++)

for(j = 0; j < X; j++)

m[i][j] = 0;

// None set.

s = 0;

// Set ten random ones to 1.

while ( s < M )

{

// Pick a random location.

i = rand()%X;

j = rand()%X;

// Has it already been set?

if ( m[i][j] == 0 )

{

// No! Set it.

m[i][j] = 1;

// And remember to count it.

s += 1;

}

}

Paul