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.
"Copy Stamp SOP" attribute creation issue ...
1235 4 1- Masoud
- Member
- 398 posts
- Joined: Aug. 2015
- Offline
- Aizatulin
- Member
- 470 posts
- Joined: July 2005
- Offline
- ziconic
- 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:
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.
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
- BabaJ
- Member
- 2024 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.
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
- Aizatulin
- Member
- 470 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).
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