This invention discloses a method for generating matrixes including: a, randomly generating a sparse matrix P of k lines and n-k columns, b, getting a generated matrix G=[Ik P] from said sparse matrix P, checking the matrix H=[PT In-k], in which, Ik is the unit matrix of k lines and k columns, the PT is the transposed matrix of P, c, carrying out initial transformation to said checked matrix H to let it meet the preset re-distribution of columns to get the transformed check matrix H, d, checking if there are short rings in the matrix H, e, recording the corresponding lines and columns of the short rings in H to further get the numbers corresponding to said short rings in H so as to further find out numbers corresponding to those in the random matrix P and H, f, regulating the code re-distribution corresponding to said line and column number in P, g, repeating said step b to f and short rings do not exist in H.