Last active
July 5, 2017 14:19
-
-
Save JokerMartini/fe7ac200bc315e43e77f to your computer and use it in GitHub Desktop.
Maxscript: This function will randomly generate an array of values which added together equal the difference between he min and max values supplied. For example if you need 5 random values which added together equal 100, this function would return: #(20,18,15,30,17)
This file contains 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
fn GenRandomSumValuesArray numParts:4 minVal:0 maxVal:100 = | |
( | |
local parts = #(minVal,maxVal) | |
/* generate random numbers */ | |
while parts.count < numParts+1 do | |
( | |
appendIfUnique parts (random minVal maxVal) | |
) | |
sort parts | |
/* now collect values which will add up to inital value */ | |
local values = #() | |
for i = 1 to parts.count-1 do | |
( | |
append values (parts[i+1] - parts[i]) | |
) | |
--format "parts: %\n" parts | |
--format "values: %\n" values | |
values | |
) | |
GenRandomSumValuesArray numParts:5 minVal:0 maxVal:100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment