Computer Science Canada

Shuffle Algorithm

Author:  Artimes [ Fri Jun 03, 2005 10:59 am ]
Post subject:  Shuffle Algorithm

I need an algorithm that takes my 2d array (1..4, 1..4) and gives each coord (the first array in the 2d is the x, the second is the y) a number from 1 through 16. Each number must be used only once.

Thanks

Author:  rizzix [ Fri Jun 03, 2005 11:29 am ]
Post subject: 

n = y*4 + x

Author:  Artimes [ Fri Jun 03, 2005 11:37 am ]
Post subject: 

Wouldn't that give me the same output every time?

Author:  lyam_kaskade [ Fri Jun 03, 2005 11:41 am ]
Post subject: 

code:

for y:0..3
    for x:0..3
       array (x,y):=(y*4+x) + 1
    end for
end for

Author:  GlobeTrotter [ Fri Jun 03, 2005 4:38 pm ]
Post subject: 

Artimes wrote:
Wouldn't that give me the same output every time?


Yes it would, I don't know what these people are talking about.

First go through and assign them normal values, in order 1 - 16 then,
go through the two degrees in nested for loops. In these loops pick a random numer between 1 and 16 and swap the given element with the random one.

Author:  Artimes [ Fri Jun 03, 2005 8:11 pm ]
Post subject: 

Thanks GlobeTrotter, I got it workin'! Very Happy


: