Last active
October 13, 2020 14:46
-
-
Save arifsuhan/af53af3937bb9d045f06d6cbe308370d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://stackoverflow.com/questions/21782329/generate-n-random-numbers-whose-sum-is-a-constant-k-excel | |
| # https://stackoverflow.com/questions/7289136/how-to-make-5-random-numbers-with-sum-of-100 | |
| # https://stackoverflow.com/questions/18659858/generating-a-list-of-random-numbers-summing-to-1 | |
| # can i call this - Dirichlet distribution like ? | |
| from random import random | |
| from random import randint | |
| def gen(l,h): | |
| return round( l + random() * (h-l) ) | |
| def fn_duration(total_clip_time, shorten_clip_time, n): | |
| cut_point = [] | |
| clip_point = [] | |
| low = 0 | |
| r = total_clip_time/n | |
| # find points | |
| for i in range(n-1): | |
| high = int( shorten_clip_time/2 ) | |
| temp = randint(low,high) | |
| shorten_clip_time -= temp | |
| cut_point.append(temp) | |
| cut_point.append(shorten_clip_time) | |
| # make | |
| if max(cut_point) <= r/2: | |
| clip_point = [randint(r*x, int(r*(2*x+1)/2)) for x in range(n)] | |
| else: | |
| print("not possible to cut") | |
| result = [ [ clip_point[i], clip_point[i] + cut_point[i] ] for i in range(n) ] | |
| return result | |
| how_many = 20 | |
| limit = 180 | |
| total = 18000 | |
| fn_duration(total, limit, how_many) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment