A clean way to randomly and evenly randomize integers?

   730   4   1
User Avatar
Member
58 posts
Joined: 3月 2018
Offline
I have a scene with about 50 ropes, I made about 20 textures, I want to generate a random index I can use in my shader to tell it which texture to use. I am using "cluster", with class I got from "connectivity". This does essentially what I want, however, since the class numbers are close to each other, it is "clustering" them, so for instance you see 3 next to each other using the same texture. I feel like I fiddled with all the options on "cluster" and cannot really shake this.

Someone came up with this for me, but it leaves some being used 4 times, and others none. I wish there was a way to "relax iterations" like there is with a scatter to get an even distribution.

int grpCnt  = 10; //Number of groupings
i@myGrp = int( rand(@class) * grpCnt );//Randomize order


Thanks!
User Avatar
Member
222 posts
Joined: 5月 2017
Offline
Hi, try the approach in the hip file, it will ensure that the next texture has a different id.

Image Not Found

Attachments:
Rand_Avoid_Previous.hiplc (117.9 KB)

User Avatar
Member
58 posts
Joined: 3月 2018
Offline
viklc
Hi, try the approach in the hip file, it will ensure that the next texture has a different id.

Image Not Found

Thanks so much for this, that is an interesting approach!
User Avatar
Member
3 posts
Joined: 2月 2011
Offline
Another simple trick is to use random_sobol() instead of rand(). Its designed to give a more evenly spread-out distribution.
Edited by Ankit_Pruthi - 2024年8月1日 01:17:42
User Avatar
Member
58 posts
Joined: 3月 2018
Offline
Ankit_Pruthi
Another simple trick is to use random_sobol() instead of rand(). Its designed to give a more evenly spread-out distribution.
That is exactly what I wanted, thank you! I did not know about that function.
  • Quick Links