
-----------------------------------
Artimes
Fri Jun 03, 2005 10:59 am

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

-----------------------------------
rizzix
Fri Jun 03, 2005 11:29 am


-----------------------------------
n = y*4 + x

-----------------------------------
Artimes
Fri Jun 03, 2005 11:37 am


-----------------------------------
Wouldn't that give me the same output every time?

-----------------------------------
lyam_kaskade
Fri Jun 03, 2005 11:41 am


-----------------------------------

for y:0..3
    for x:0..3
       array (x,y):=(y*4+x) + 1
    end for
end for

-----------------------------------
GlobeTrotter
Fri Jun 03, 2005 4:38 pm


-----------------------------------
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.

-----------------------------------
Artimes
Fri Jun 03, 2005 8:11 pm


-----------------------------------
Thanks GlobeTrotter, I got it workin'! :D
