samedi 30 décembre 2017

How can I generate random numbers in slabs of a range in Python3?

Suppose I want to generate 10 random numbers between 1 to 100. But I want to pick numbers randomly from each number of sets like 1-10, 11-20, 21-30,.... So that It does not come out like this: 1, 7, 26, 29, 51, 56, 59, 89, 92, 95. I want to pick numbers randomly like this: 7, 14, 22, 39, 45, 58, 64, 76, 87, 93.

I have created a code sample. But I can't figure out later part of the problem.

import random

def getInteger(prompt):
    result = int(input(prompt))
    return result

range1 = getInteger("Please Enter Initial Range: ")
range2 = getInteger("Please Enter Ending Range: ")
range3 = getInteger("Please Enter the Range size: ")

myList = random.sample(range(range1, range2), range3)

myList.sort()

print ("Random List is here: ", myList)

I am new to programming. I googled about it, but did not find any solution. Thank you guys in advance...




Aucun commentaire:

Enregistrer un commentaire