basic issue, 3 digit ints

sacredgeometry's icon

hi i was wondering if theres a way to get 3 digit integers...so 40 is represented with 040 or otherwise if theres a better way to generate random colour values....... i am at the moment randomly generating three ints to the range of 255 then sprintf'ing them. this is fine if all the values are in over 100 but if one is under it ruins this patch.

if this is the best way to do this? is there a way to add a prefix of 0 depending on its value...sorry i am new and cant get my head around if statements in max i might use JS instead but i would like to practice using max over regular scripting.

spectro's icon

As far as setting colour values go, depending on what objects you are setting, it may be possible to use floats (0.0 - 1.0) rather than ints. Wheter that resolves your patch issue is another questtion.

As far as integer padding - I have a vague recollection that this is a modified version of a patch I downloaded from this site quite some time ago. It has the added "feature" of specifying the number of zeroes to pad your output with and handles negative values (more or less).

Max Patch
Copy patch and select New From Clipboard in Max.

Luke Hall's icon

You can do this all with [sprintf symout %03ld] where the 0 sets the padding to use and the 3 is the number of places.

lh