shuffling branches
full ruby implementation