VEX Rand Function: different seeds, same result? [{SOLVED}]

   300   2   0
User Avatar
Member
1013 posts
Joined: 4月 2017
Offline
Hi!

I was exporting a tree from Speedtree and wanted to use the s@hierarchy to generate different colors. I used random_shash on the s@hierarchy to get the seeds.

I noticed I'm getting the same results and I'm wondering if the seed is just too big of a number. I've isolated 3 primitives of my asset with integer values:
0: 389075844
1: 389075843
2: 389075842

...I get the same color when using the rand function with those seeds.

Any tips on getting this to work?

-Olivier
Edited by olivierth - 2024年5月22日 10:41:07
User Avatar
Member
1013 posts
Joined: 4月 2017
Offline
Ahhh! ok, I think I found a workaround.

The trick was to use a step between my random_shash and rand functions. I used the random_ihash function that takes an integer as a seed and generate a new, completely different integer. It convert like this:

0: 389075844 = -722655334
1: 389075843 = -445310208
2: 389075842 = -1444283786

When using those new values, the colors are different! Here's the code:
string last = split(s@hierarchy, "/")[-1]  // isolate the last part of the hierarchy
int number = random_shash(last);  // rand integer from string
int ihash = random_ihash(number);  // rand integer from integer
@Cd = rand(ihash);
Edited by olivierth - 2024年5月22日 10:39:57
User Avatar
Member
7863 posts
Joined: 9月 2011
Online
olivierth
Hi!

I was exporting a tree from Speedtree and wanted to use the s@hierarchy to generate different colors. I used random_shash on the s@hierarchy to get the seeds.

I noticed I'm getting the same results and I'm wondering if the seed is just too big of a number. I've isolated 3 primitives of my asset with integer values:
0: 389075844
1: 389075843
2: 389075842

...I get the same color when using the rand function with those seeds.

Any tips on getting this to work?

-Olivier

random() for integers, rand() for floats
  • Quick Links