Different result for the same 'rand(1)' expression

   308   3   1
User Avatar
Member
48 posts
Joined: 2月 2013
Offline
I added a 'Attribute wrangler' and use this code to create xx primitive attribute :
f@xx = rand(1);

the result is : 0.00292516

but if I add attribute using 'attribute create' and use this code :
rand(1)

the result is : 0.800464

Why are they different ?
User Avatar
Member
2041 posts
Joined: 9月 2015
Offline
Likely because they are two different functions - Only the same in name.
One is an Hscript function the other vex.

My Guess - The Hscript one has been around for a long time before the vex context came along.
But when they wrote the rand function for vex, I think they made some decisions/considerations about that to 'work better' in a vex context. Being that both functions purpose is to produce a random result - I don't think they 'felt' the need and try to keep the results the same for same seed values.

If you do need some consistency between both contexts, you should be able to go with one rand() in one context and simply reference the result for another context.
Edited by BabaJ - 2024年3月15日 13:00:25
User Avatar
Member
48 posts
Joined: 2月 2013
Offline
BabaJ
Likely because they are two different functions - Only the same in name.
One is an Hscript function the other vex.

My Guess - The Hscript one has been around for a long time before the vex context came along.
But when they wrote the rand function for vex, I think they made some decisions/considerations about that to 'work better' in a vex context. Being that both functions purpose is to produce a random result - I don't think they 'felt' the need and try to keep the results the same for same seed values.

If you do need some consistency between both contexts, you should be able to go with one rand() in one context and simply reference the result for another context.

Thanks. I just curious why they produce different output. I didn't know the other is Hscript. I'm new to Houdini scripting and thought they are all vex :-).
User Avatar
Member
8555 posts
Joined: 7月 2007
Offline
metaclay2
I added a 'Attribute wrangler' and use this code to create xx primitive attribute :
f@xx = rand(1);
if you really want the same result as Hscript expression in the parameter provides you can use hscript_rand() function
f@xx = hscript_rand(1);
however I wouldn't recommend using it without the specific need for the match
Edited by tamte - 2024年3月15日 13:26:38
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links