a value returned by random expression

   8959   19   1
User Avatar
Member
21 posts
Joined: Jan. 2013
Offline
Hello.
I'm looking up about rand() expression function using HScript.

Could you tell me the range of a value returned by rand()?
Which pattern below is the range?
0<n<1
0<=n < 1
0<n<=1
0<=n<=1
where n is returned by rand().

In addition,I couldn't make out the difference between rand() and oldrand().
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
rand()is going to give you a random number based on the input value, if you want to limit that value you use fit01()

Rob
Gone fishing
User Avatar
Member
30 posts
Joined: Sept. 2010
Offline
I think rand() is going to return a number in the 0 to 1 range. You can use fit01() to map that value to a range defined by two arbitrary numbers.
User Avatar
Member
21 posts
Joined: Jan. 2013
Offline
Thanks for your replies

But just so import for me to know that the value may include zero or one.
Cuz I often use int( rand(seed)*number ) and then judge the value by if().

If the range were 0<n<1, int(n) will be just 1.
if 0<=n<=1 or 0<n<=1,it will be 0 or 1.
So whether including 0 or 1 is very important to use conditional rules.

The random function of Python is 0<=n<1.
But I couldn't look it up about HScript.
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
dan.baciu
I think rand() is going to return a number in the 0 to 1 range. You can use fit01() to map that value to a range defined by two arbitrary numbers.

Yes your correct very much my mistake there….
Gone fishing
User Avatar
Member
30 posts
Joined: Sept. 2010
Offline
I believe rand() output is in the 0<n<1 range.
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
between 0<= rand <= 1 , Not 0 < rand < 1 !
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
Check the JK attr in the spread sheet from this file !

Attachments:
JKRand.hip (59.6 KB)

https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
21 posts
Joined: Jan. 2013
Offline
Wow.
Thank you!
I got the answer.
rand() is 0<=n<=1.
This is it.
User Avatar
Member
8583 posts
Joined: July 2007
Offline
Joker386
Check the JK attr in the spread sheet from this file !
it's difficult to know for sure by such example

in the spreadsheet I can see one 0 and two 1's
but if I append blast sop with point group expression @jk!=0 I get 1 point and @jk!=1 keeps 0 points
so clearly some rounding happening in one or both cases

on top of that changing the expression to floor(rand($PT)) returns all 0's
and changing it to ceil(rand($PT)) returns all 1's except one meaning that one seed returned pure 0 value (seed 2250372)
this was on sample of 5 000 000 seeds
tried for range from -500 000 000 to +500 000 000 seeds, still no 1's
so till this point it looks to me as 0<=n<1
but I guess there may be some seed outside this range with value of 1
can someone provide specific seed where floor(rand(seed)) returns 1?
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
21 posts
Joined: Jan. 2013
Offline
Actually “1.0” values in the spread sheet seem not to be the same with real 1.0
some expressions such as if($jk==1.0,a,b) doesn't work well.
So, the hypothesis of 0<=n<1 is possible.
I guest the values in the spread sheet are automatically rounded.
Now I'm looking for the precision adjustment but couldn't find where.
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
yes, I think Spread sheet rounded some numbers too , But I think rand function turn number between 0 and 1 , I used it in some of my personal project ,Sorry I don,t have Houdini right now , so I,ll check these discussion later :?
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
User Avatar
Member
4189 posts
Joined: June 2012
Offline
It's easy to check - set the jk attribute to 16bit and the rounding is much more apparent. I would not think the spreadsheet is rounding. It appears to be floating-point precision rounding. Test attricreate at 32 and 64 bit, the rounding is effected.

The if==1.0 statement works fine in the attached.

Attachments:
jkrand_119Edit.hip (62.3 KB)

User Avatar
Member
21 posts
Joined: Jan. 2013
Offline
You bet the conversion between binary and decimal number might generate an error.
Longer the decimal point is,less accuracy the result is.
16bit float can express only short-wide range.
So I can almost believe the truth of the spread sheet as for 16bit.
But as for 32bit or 64bit,I can't believe it at all.
The spread sheet doesn't support 32/64bit?
Mathematically the conversion of “1.0” from decimal to binary should not generate an error.Cuz both types can express “1.0” accurately.
My head is crashed out :cry:
User Avatar
Member
4189 posts
Joined: June 2012
Offline
Why do you say the spreadsheet is 16bit?

6 significants is 32bit. Houdini is generally single precision between nodes afaik

Edit:
It's all here in the documents
http://www.sidefx.com/docs/houdini13.0/nodes/sop/attribcast [sidefx.com]
User Avatar
Member
21 posts
Joined: Jan. 2013
Offline
It means I doubt the spread sheet values don't express complete exact precision.
It's a good idea to use 16bit float for rand() function.
But I have something on my mind for the behavior.
User Avatar
Member
7726 posts
Joined: July 2005
Offline
CaramelPanda
It means I doubt the spread sheet values don't express complete exact precision.

Unfortunately, double precision floating isn't currently supported spreadsheet. Double precision floating point values will be casted to single precision and then displayed using a maximum of 6 significant decimal digits. For parameter fields, they are also displayed using a maximum of 6 significant decimal digits.

Feel free to log an issue using the Support menu above on this website for the spreadsheet to show double precision attribute values with greater significant digits. As I recall, there has been various discussions/debates on what the maximum significant decimal digits should be. On one side, you have the more scientifically minded group saying you should use the largest possible value, while the artistic camp feels that the extra digits just provides noise (much truer for the parameter fields than the spreadsheet). And then we have the two (somewhat orthogonal) camps either arguing that this should be user configurable vs the usability camp that you should not have too many choices.
User Avatar
Member
4189 posts
Joined: June 2012
Offline
The spreadsheet could have a ‘basic mode’ and ‘scientific mode’. Like the Calculator app on iPhone; vertically it's good for simple calculations, rotated to the side reveals more power.
User Avatar
Member
21 posts
Joined: Jan. 2013
Offline
In summary, the range of HScript rand() is 0<=n<1.
But Houdini Spread Sheet shows the value as a single precision float.
This thread was so meaningful for me.
Thank u ,sir
User Avatar
Member
1391 posts
Joined: Dec. 2010
Offline
MartybNz
It's easy to check - set the jk attribute to 16bit and the rounding is much more apparent. I would not think the spreadsheet is rounding. It appears to be floating-point precision rounding. Test attricreate at 32 and 64 bit, the rounding is effected.

The if==1.0 statement works fine in the attached.

That's important Tip ! :idea:
https://www.youtube.com/c/sadjadrabiee [www.youtube.com]
Rabiee.Sadjad@Gmail.Com
  • Quick Links