make sampling of segments uniformly at random and add unit test