asdfarkangel

28-10-2010, 04:04 PM

Hi I hope some more experienced people can help me. I need a procedure that sets all 100 values of a 10x10 matrix to either 0 or 3(Randomly). Now my solution looked like this:

type matrix100=array[1..10] of array[1..10] of byte;//This is the type for the matrix

Procedure fill_matrix(m:matrix100);

var

i,j,rand:byte;// I use byte because none of these values should be too big.

Begin

for i:=1 to 10 do

for j:=1 to 10 do //double for cycle to set all values of the matrix

begin

randomize;

rand:=random(255);

if (rand mod 2=1) then m[i][j]:=3 else m[i][j]:=0; {This was an easy way of choosing in setting each value to either 3 or 0}

end;

end;

This however does not give me the wanted result. It sets all values either to just 3 or just 0 and I don't know for sure why because that's why I call randomize inside the for loop. I think it's because as far as I know it uses the system clock for randomization and it's just miliseconds that separates those for loops. Be it this or not I can not find a better way on my own. Can someone help me out?=)

type matrix100=array[1..10] of array[1..10] of byte;//This is the type for the matrix

Procedure fill_matrix(m:matrix100);

var

i,j,rand:byte;// I use byte because none of these values should be too big.

Begin

for i:=1 to 10 do

for j:=1 to 10 do //double for cycle to set all values of the matrix

begin

randomize;

rand:=random(255);

if (rand mod 2=1) then m[i][j]:=3 else m[i][j]:=0; {This was an easy way of choosing in setting each value to either 3 or 0}

end;

end;

This however does not give me the wanted result. It sets all values either to just 3 or just 0 and I don't know for sure why because that's why I call randomize inside the for loop. I think it's because as far as I know it uses the system clock for randomization and it's just miliseconds that separates those for loops. Be it this or not I can not find a better way on my own. Can someone help me out?=)