# grouping 1 random point

## Recommended Posts

Hello

I am trying to group only 1 random point on a grid and change it based on a seed..... I know how to group many random points... like this :

rand(@elemnum) < 0.3

but how can I randomly group only ONE point randomly ? I tried something like this:

rint(rand(@ptnum)<0.001)

It works i think but this is not a very robust way of doing things....any suggestions ?

##### Share on other sites
`i@group_single_point = floor(rand(chf('seed'))*@numelem) == @elemnum;`

Something like this should work

• 1
• 1

##### Share on other sites

Thank you jkunz this works perfectly...Not entirely sure I know what is going on in the code though haha... What exactly is @numelem ?

Cheers

##### Share on other sites

@numelem is the total number of elements being processed.  Depending on the what the wrangle is set to operate on (points, vertices, prims, or detail).

You could use npoints() or nprimitives() vex functions instead if you want.

The code is generating a random number between 0 and 1.  This is then scaled to fit the number of points (multiplying by @numelem).  floor() function eliminates anything after the decimal, so we have a whole number.  Then we check if it matches the current element number (@elemnum).  If it matches, this will evaluate to 1, adding it to the group, the rest of the points that don't match will evaluate to 0 and not be included in the group.

Is that clear?  Let me know if you have any more questions.

##### Share on other sites

Hi jkunz,

I think i get it now. this is a really great method...

I tried to replace elemnum and numelemwith npoints and ptnum but it doesn't seem to work . So i did this:

i@group_single_point = floor(rand(chf('seed'))*@npoints) == @ptnum;

wouldn't this be doing the same thing ?

Thank you for you help !

##### Share on other sites

The variable for total number of points is @numpt.

There is a function npoints() which is different for a variable.  npoints(0) (the zero specifies the input geometry) will return the same result as @numpt.

This part of the docs might be worth looking at: http://www.sidefx.com/docs/houdini/vex/snippets.html#indexing

##### Share on other sites

Makes sense. thanks for the help jkunz

## Create an account

Register a new account