I need randomly generated by a two-dimensional nn array. In this example, n = 10 The array should have this structure. An example:
$ igra [] = array (0,1,2,3,4,5,6,7,8,9); $ Game [] = array (6,9,1,5,0,2,7,3,4,8); $ Igra [] = Array (2,5 .................... $ igra [] = Array (1,7 .......... ........... $ igra [] = array (5,4 ................... $ igra [] = array (4,2) ................... $ IGRA [] = array (9.0 ..................... $ Igra [] = Array (8,3 ..................... $ igra [] = array (7,6 ......... .. ......... $ igra [] = Array (3,8 .................... Where
`$ igra [x] [z]! = $ Igra [y] [z]` (x = {0}}, y = {0}}; As you see, it is similar to a matrix of numbers, every row and column is also made up of 0-9 numbers, and once in each row or in each column Do not happen twice how to generate such an array, and each time randomly.
$ n = 10; $ v1 = category (0, $ n-1); $ v2 = category (0, $ n-1 ($ V1); Changes ($ v2); Foreach ($ v1 $ x = & gt; $ value) foreach ($ y2 as $ v2) $ array [$ y] [$ x] = $ Value ++% $ n; It must be really fast algorithm, because it involves Ves only produces two random arrays and does not include swapping of all types. It should also be random, but I can not prove it. (At least I do not know anything like that.) This is a customized version of a very simple algorithm:
The first non-random matrix is created (by the way) Imagine that we only want 5 * 5, 10 * 10):
0 1 2 3 4 1 2 3 4 0 2 3 4 0 1 3 4 0 1 2 4 0 1 2 3
In this matrix we now swap random columns. As we do not make changes in our columns, your rules are followed. Then we randomly swap the rows.
Now, as you can see, the above algorithm does not swap anything and it does not produce either the matrix above. This is because it already generates columns and rows to swap ( $ v1 and $ v2 ) and then directly writes it in the right position in the resulting array.
Edit: Just a few benchmarking was done: $ n = 500 takes 0.3 seconds.
Edit2: After taking the rear with the forward loop only takes 0.2 seconds.
Comments
Post a Comment