I'm trying to generate n number of times a random integer from 1-100. But first from 1 to 25, the probability of generating it is 1/8. from 26 to 50 is a chance of 1/2. the subrange 51 to 75 is 1/4, and the sub range from 76 to 100 has a 1/8 chance of generating. I know how to generate a random int 1-100, but I'm having trouble coming up with an algorithm with the sub-ranges. Could someone guide me in the right direction? I don't want to use any shortcuts like built in functions if there are for this. I'm also coding in python.
import random
numOfTimes = int(raw_input())
counter = 0
while counter < numOfTimes:
chance = random.randint(1,8)
if chance == 1:
randomNumber = random.randint(1,25)
if chance == 2 or 3 or 4 or 5:
randomNumber = random.randint(26,50)
if chance == 6 or 7:
randomNumber = random.randint(51,75)
if chance == 8:
randomNumber = random.randint(76,100)
counter = counter + 1
print randomNumber