Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Sudoku Matrix Date: Mon, 5 Mar 2012 07:45:11 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 20 Message-ID: <jj1qu7$f95$1@newscl01ah.mathworks.com> References: <jj1335$8e8$1@newscl01ah.mathworks.com> <jj1i51$ke1$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-01-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1330933511 15653 172.30.248.46 (5 Mar 2012 07:45:11 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 5 Mar 2012 07:45:11 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:759870 "Roger Stafford" wrote in message <jj1i51$ke1$1@newscl01ah.mathworks.com>... > "Ryan" wrote in message <jj1335$8e8$1@newscl01ah.mathworks.com>... > > I am trying to generate a random matrix using only numbers 1-9 once each. I have figured out how to make one with the same total sum as the Sudoku matrix however it doesn't guarantee the conditions of a proper Sudoku matrix. Does any one have any ideas on how to create this random Sudoku matrix? > - - - - - - - - - > I = [randperm(3),randperm(3)+3,randperm(3)+6]; > J = [3*randperm(3)-2,3*randperm(3)-1,3*randperm(3)]; > S = zeros(9); > S(I+9*(J-1)) = randperm(9); > > Roger Stafford -- - - - - - - - - I think I misunderstood what the problem is. If you use each of the numbers 1:9 just once each, then any random placement of these nine numbers anywhere in the matrix should be valid. Therefore the following should generate what you want: S = zeros(9); p = randperm(81); S(p(1:9)) = 1:9; If this isn't what you are asking for then could you please state what it is you consider "a proper Sudoku matrix". Roger Stafford