I know the solution to the random reordering has already been handled, but here is a solution that I find more mathematically satisfying.
1. Assign each die a random x, y coordinate
a. The coordinates should be real numbers (i.e. doubles )
b. If you prefer integers, then the range of possible values for each dimension should be significantly larger than the corresponding grid dimension and a multiple of the grid dimension.
For a 6x16 grid, use x=rand()%(6*6), y=rand()%(16*16)
2. Sort the dice by their y coordinate *in place*
3. Partition the list into h equally sized groups where h = height of dice grid
For a 6x16 grid, obviously partition into 16 groups of 6 coordinate pairs
4. Sort the dice in each partition *in place*
5. The list should represent a random distribution representing random re-ordering over a fixed size grid
So, for the die in group 4 at slot 2, it should go to Grid location row 4, column2
It may not be more efficient (haven't done the analysis), and it might be more troublesome to implement, but it is an interesting solution, no?