Generate range of random numbers and seed to randomize.

   1238   3   1
User Avatar
Member
128 posts
Joined: Sept. 2018
Offline
I want to create a detail attribute in VEX that randomly selects numbers between 1 and 5 and I want to use the iteration number in a for-each loop as the seed to shuffle between the numbers 1 to 5. Been having some trouble all morning trying to figure it out. Hope you can help.
User Avatar
Member
6 posts
Joined: March 2019
Offline
Hello,

A possible way may be using "sample_discrete" [www.sidefx.com] VEX function.

=e
Edited by eriksky - Jan. 5, 2023 15:49:56

Attachments:
sample_discrete_for_loop.hipnc (53.3 KB)

User Avatar
Member
466 posts
Joined: Aug. 2014
Offline
Try this in a detail wrangle, with foreach_countconnected to second input:
int iter = detail(1, "iteration");
i@num_rnd = int(rand(iter) * 5) + 1;

Example output for 100 iterations:
3152111453115511555142124542515455352525224235514222554453113115132144314525544324311322441345342534

@eriksky beat me to it, though with a different function.
Edited by ajz3d - Jan. 5, 2023 15:54:42
User Avatar
Member
128 posts
Joined: Sept. 2018
Offline
Awesome thank you!!!! Works great!

int iter = chi("iteration");
i@num_rnd = int(rand(iter) * 4) + 2;

What I ended up doing.

Vincent Griffith
Edited by VGriffith - Jan. 5, 2023 16:36:39
  • Quick Links