"Copy Stamp SOP" attribute creation issue ...

   1252   4   1
User Avatar
Member
407 posts
Joined: Aug. 2015
Offline
Hi;

In a “Copy Stamp SOP”, I tried to create a random integer attribute ranged from 0 to 10, but it creates values from 2 to 9.
How can I fix this?



Thanks for helping.
Edited by Masoud - May 30, 2020 06:14:28

Attachments:
CopyFit.jpg (646.1 KB)
CopyFit.hip (70.0 KB)

Masoud Saadatmand (MSDVFX)
User Avatar
Member
475 posts
Joined: July 2005
Offline
Hi,

there is no guarantee, that every random number will be generated. If you multiply @ptnum with a float value (like 0.5 for example)

the ids will change.
User Avatar
Member
73 posts
Joined: March 2020
Offline
The other issue with your expression is that fit01(stamp(“..”, “myId”, 0), 0, 10)) doesn't ensure a uniform distribution because the value of the fit01 expression is being rounded to the nearest integer, i.e. 0-0.499 maps to 0, 0.5-1.499 maps to 1, 1.5-2.499 maps to 2, …, 9.5-10 maps to 10, which means you will get more numbers in the 1-9 range than 0's or 10's.

To get an even distribution between 0 and 10, you need something like:
int(fit01(stamp("..", "myId", 0), 0, 11))

Finally, as Aizatulin said, if you are trying to shuffle a list of numbers rather than generate a random number sequence, you may want to use a different approach, e.g. using the sort sop to jumble up an attribute that is initially assigned to @ptnum.
Edited by ziconic - May 30, 2020 18:23:46
User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
The reason your only getting values from 2-9 is because you have a low input sampling to work with, hence less chance of getting 0s and 10s.

Increase your grids rows and columns and you'll see you get more 0s and 10s.

If you don't want to increase your grids rows and colummns but for whatever reason want to get some 0s and 10s in there just add a seed parameter to your rand expression and you can get some 0s and 10s easily.
Edited by BabaJ - May 30, 2020 15:40:38

Attachments:
CopyFit-1_v0.hiplc (96.2 KB)

User Avatar
Member
475 posts
Joined: July 2005
Offline
If you increase the number of grid points, you can see the effect, which ziconic discribed. The amount of 0s or 10s is roughly the

half of any other id. Using int() or floor() will shift the intervals from (i-0.5, i+0.5) to (i, i + 1), where each number from these

intervals will be mapped to i (boundary points can be ignored). Doing this, will double the probabilty of getting 0s but the 10s will

disappear. Now 10 different ids are possible (0,1,2,3,4,5,6,7,8,9).
  • Quick Links