How is posible to do a random function with specif range, example i want random from 1.86 to 2.85 and i dont want to lower that 1.86 or go beyond 2.85,
i just stamping a book to randomize the thikness of the cover, i am using rand($PT) i know or the idea is to use some Fit function might be something like fit( “rand($PT)” and then something else, but it just goes from -1 to 1
There are several different fit expressions. You are referring to the fit11 one, which is between -1 and 1. You just want regular old fit.
exhelp fit float fit (float num, float oldmin, float oldmax, float newmin, float newmax) Fits a value from one range to another.
Return a number between newmin and newmax that is relative to num in the range between oldmin and oldmax. If the value is outside the old range, it will be clamped to the new range.
EXAMPLES | fit(3,1,4,5,20)=15 |
RELATED fit01 fit11 fit10
Graham Thompson, Technical Artist @ Rockstar Games
well i did a fit01 didnt understand why they are several tipes of “fit”s functions but look like with that you tell houdini to do a random $PT from the -.0075 to -.04
What the fit() is doing is taking your source number, which is in a certain range, then remapping it to within another range.
You say you want a random number between 1.86 and 2.85. Since the rand() function will give you a number between 0 and 1, you basically remap 0-1 to be 1.86-2.85. fit(rand($PT), 0, 1, 1.86, 2.85)
fit01() is basically fit() with 0 and 1 as the old min/max.
Graham Thompson, Technical Artist @ Rockstar Games
oh graham i see now, instead of doing a new expresion, we are just making the range of the fit expresion bee instead of 0 to 1, of the value i want to the other value i want Cool thank for explaining that so easy now i understand it.
weird thing because i was doing with the other Fit and looks that was working ok, but i am not sure, this is my second attempt to Stamp things.
Alternatively, without using fit, you can manipulate the result of the rand($PT) function arithmetically in order to place it within your desired range.
So, since you want a random number between 1.86 and 2.85, what about something like
rand($PT)*(0.99) + 1.86
in other words,
rand($PT)*(2.85-1.86) + 1.86
and in general terms,
(random value from 0 to 1 inclusive)*(top of range - bottom of range) + (bottom of range)