Function for the generation of a weighted random sequence
removed some commented lines
Re-organized some condtions and implemented the shuffled control system