unique random integer from range per point

   7741   2   1
User Avatar
Member
126 posts
Joined: April 2014
Online
I am stumped at this probably simple fundamental problem.

I have n number of points and I need to assign each a unique integer between the range of 0 and 500.
Assigning the random value is not the problem as I am not that much of a newb but it is making sure that number is not already taken that has me.

How can I ensure that each point gets a unique and non shared random value?

My thought is to put the previously selected values into an array and check that against each new selection. If the number has already been selected, try again. I am just not yet comfortable writing that in vex or Vop even.
Assuming it would involve a for next loop?

suggestions much appreciated
User Avatar
Staff
6793 posts
Joined: July 2005
Offline
Line SOP, generate 501 points.
Enumerate SOP. Set to points. Creates ‘index’ attribute going 0 to 500
Sort SOP. Sort points randomly.

This creates a bin of random numbers you can draw from without replacement. So, in your geometry of ‘n’ points, you want to just pick the first ‘n’ points from this bin to get your random numbers with no repeats.

To your geometry with N points append an attribute copy. Change the Attribute Name to index and set the second input to be the sort sop.
User Avatar
Member
126 posts
Joined: April 2014
Online
that works! - thank you
  • Quick Links