I'm trying to create random integer values to select random object from a switch node and copy those with a copy stamp onto points. But i'd like to avoid duplicate values. Anyone please?
I'd be fine with a successive incremented value as well in my case scenario assuming i can define the min / max range. No clue either how to write that.
Thanks,
A.
(rand($PT))*"integer" + avoiding duplicate value?
1966 1 0-
- Adriano
- Member
- 411 posts
- Joined: June 2015
- Online
-
- Enivob
- Member
- 2658 posts
- Joined: June 2008
- Offline
With a small set of items it is not going to make that much difference. But you can leverage Python's random.sample() to randomly pull from a list of candidates. If your geometry point count ever exceeds the list length then you will experience a duplicate.
import random geo = hou.pwd().geometry() # Create the point attribute value, giving it a default value and store the returned hou.Attrib object. rnd_index = geo.addAttrib(hou.attribType.Point, "rnd_index", 0) sample_set = [0,1,2,3,4,5,6] for point in geo.points(): value = random.sample(sample_set, 1) point.setAttribValue(rnd_index, value)
Edited by Enivob - Aug. 12, 2017 08:53:21
Using Houdini Indie 20.5
Windows 11 64GB Ryzen 16 core.
nVidia 3060RTX 12BG RAM.
Windows 11 64GB Ryzen 16 core.
nVidia 3060RTX 12BG RAM.
-
- Quick Links

