Q:

How to scale a number within a given range in python

I want to scale a number to a given range of numbers. For example, Given a range of possible number is between 0 to 86. If the program generates a number outside this range then it should scale to any number between this range. Also, If the program generates a number within the range i.e. between 0 to 86 then it should keep the original.    

A:

The word "scale" is ambiguous in your problem statement. Maybe you want to have a number within your range that you can do by taking mode. As per your example if 100 is your number then it should become within the range 0 to 86. Then you should do it like. 
Num = Num % 87

and if you have range like (min, max) then 
Num = Num % ( max - min + 1) + min

