Quickest / simplest way to give each instance of my HDA a different seed value?

   3384   7   1
User Avatar
Member
146 posts
Joined: 9月 2011
Offline
As per subject - if I drop a few instances of my HDA into a scene, what's the simplest way of generating a different seed value to use within it?

I could just put a “parm_seed” parameter on the HDA's interface, but knowing me I'll forget to change it on each instance.

I suppose I could hash the node name somehow to generate a seed, given that Houdini will automatically give each instance a new name (by appending 1, 2, 3 etc on the end), but if anyone has a cheeky expression I can use it'd save me reinventing the wheel…

User Avatar
Member
899 posts
Joined: 2月 2016
Offline
interesting question.
As you suggested, I also thought of some string manipulation.


Then I rmb about the intrinsic attributes and I thought there was some intrinsic attribute storing the ID of the node. There is actually a “geometryid” intrinsic but I always get “0” as result when I try to read it.
Also, what does “primitivetokens” mean?

User Avatar
Member
8839 posts
Joined: 7月 2007
Offline
you can put opdigits(“.”) in your seed parameter
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
8839 posts
Joined: 7月 2007
Offline
Andr
Also, what does “primitivetokens” mean?
primitivetokens is just list of all possible primitive intrinsics
however which ones are applicable depends on the primitive type
the geometryid you are referring to is geometry id for packed primitives
overall you don't want to use any of the intrinsics for this purpose as they rely to the geometry and not to the node itself (and of course reading the geometry to be able to generate that geometry with different seed would be an infinite cycle)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
899 posts
Joined: 2月 2016
Offline
thanks for explaining!
User Avatar
Member
5 posts
Joined: 7月 2009
Offline
This Python expression will give you new random for each copy based on a full path to the node

import random
random.seed(hou.node(“.”).path())
return random.random()
User Avatar
Member
12 posts
Joined: 5月 2017
Offline
This is how the built-in Attribute Randomize node does it.
The following python script is in the Scripts tab > OnCreated Script of the Type Properties for the hda.
node = kwargs['node']
seed = 6173*node.sessionId()+4139;
node.parm('seed').set(seed % 10000)

Explicitly setting the seed parameter on node create is the safest approach. Basing the seed on the node name can quickly cause problems when you go to clean up your scene and re-name everything (Toootally never accidentally done that before )
User Avatar
Member
146 posts
Joined: 9月 2011
Offline
Thanks all - Leaf, that works perfectly
  • Quick Links