Have a look at my Complex Randomisation and Randomisation without repetition online demos for a couple of possible approaches.