fixed bug in random slice calculation (and refactored Slice class)

Change-Id: Ic20a4ac9568a6a55b781736469d9f3c926d7a54c