Random Material Assignment on a Grid of Planes

I have a 7x6 grid of individual planes.
I need to place a material on only 8 of the planes randomly.

I have a working routine for going through the grid and randomly assigning the materials.
It is randomly choosing of the planes in the grid to use that is stumping me.

The assignment needs to be random but somewhat evenly distributed.
I have been thinking about the algorithm quite a bit but have yet to see through to the solution.
Any thoughts?

1 Answer

1
  • Create a list of the planes.
  • In a loop, until you have 8 selected:
  • Get a random index
  • Remove plane from list and put in selected list
  • End Loop
  • Tada, you have list of 8 randomly selected planes.

As planes are removed, the list will get shorter.
In each cycle of the loop, use the list length to help generate the random index.

Right, so cycle through the list 8 times or as many times as it takes, each time selecting a plane based on a random selection of index numbers. Each selection is added to a "Selected" list and compared with the next pick. If I have already picked it in a previous loop then try again. I like it, simple and straight forward. For some reason I wanted it to be much more complex. It will be interesting to see what kind of a spread/distribution I get. I don't want the selected to be all bunched up. Thanks.