Jump to content

Using Rand


cspears2002

Recommended Posts

point_instances.hipncI'm working on a tutorial out of the "The Magic of Houdini". At the object level, I have the following nodes: geo1, geo2, geo3, geo4, geo5. I'm going to assign the geometry in these nodes to points on a grid.

In order to do this I created a node called cloud at the object level. I jumped inside the node and layed down a Grid SOP and attached a Point SOP to the grid. In the Point SOP, I clicked on the Particle tab and added an instance. The script used to select the geometry for the instance is /obj/geo`int(rand($PT)*5)+1`

I can see how the script can select geo1. This would would happen if rand($PT) generated 0. However, isn't there a danger that the script would generate a geo6 if rand($PT) generated 1? This hasn't happened to any points on the grid. Is 0 <= results of rand < 1 ? I'm going to try to attach the file in question to this post.

Link to comment
Share on other sites

There is virtually no chance that rand() will generate a zero or a one.

If you are still concerned, you can always wrap the rand around a fit01() expression to tailor the results of rand(). Also look at the floor(), round(), int() expressions and other variants to cut down the upper range.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...