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
thanks
http://localhost:48626/expressions/fit11 [localhost]
setting a random number between specific range?
57398 6 4- pelos
- Member
- 617 posts
- Joined: Aug. 2008
- Offline
- graham
- Member
- 1906 posts
- Joined: Nov. 2006
- Online
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
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
- pelos
- Member
- 617 posts
- Joined: Aug. 2008
- Offline
- pelos
- Member
- 617 posts
- Joined: Aug. 2008
- Offline
- graham
- Member
- 1906 posts
- Joined: Nov. 2006
- Online
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.
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
- pelos
- Member
- 617 posts
- Joined: Aug. 2008
- Offline
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.
this is what a idid.
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.
this is what a idid.
- riot
- Member
- 2 posts
- Joined: June 2014
- Offline
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)
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)
-
- Quick Links