pythonrandom

Generate random number between x and y which is a multiple of 5


I've read the manual for pseudo-randomness in Python, and to my knowledge, you can only generate numbers up to a given maximum value, i.e. 0-1, 0-30, 0-1000, etc. I want to:

I've looked around, and I can't find anywhere that explains this.


Solution

  • Create an integer random between e.g. 1-11 and multiply it by 5. Simple math.

    import random
    
    for x in range(20):
        print(random.randint(1, 11)*5, end=' ')
    print()
    

    produces e.g.

    5 40 50 55 5 15 40 45 15 20 25 40 15 50 25 40 20 15 50 10