switch random libraries and refactor sampling code