File size: 805 Bytes
753b40f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import random
import math

def map_to_random_milestone(num):
    """
    Maps a number to a randomly selected milestone integer (multiples of 10).
    The milestone is randomly sampled from [ceiling to next 10, ceiling of 2*num to next 10].
    
    Args:
        num: Input number (float or int)
    
    Returns:
        A randomly selected milestone integer ending with 0
    """
    # Find the smallest milestone (multiple of 10) larger than num
    min_milestone = math.ceil(num / 10) * 10
    
    # Find the smallest milestone larger than 2 * num
    max_milestone = math.ceil(2 * num / 10) * 10
    
    # Generate all possible milestones in the range
    milestones = list(range(min_milestone, max_milestone + 10, 10))
    
    # Randomly select one milestone
    return random.choice(milestones)