Randomly picking from set value list

   9292   8   2
User Avatar
Member
169 posts
Joined: April 2014
Offline
How does one create an expression where the value would be randomly picked from a list of 9 pre-determined values.

Thank You!
Winter is coming!
User Avatar
Member
4729 posts
Joined: Feb. 2012
Offline
Depending on your seed you can do this using Python:

import random
random.seed(lvar('PT'))
return random.choice()
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
What about using hscript or VEX rand() in conjunction with fit01().

i.e:
hscript
fit01(rand($PT), 0, 9)

or
VEX
fit01(rand(@ptnum), 0, 9)
User Avatar
Member
169 posts
Joined: April 2014
Offline
PradeepBarua
What about using hscript or VEX rand() in conjunction with fit01().

i.e:
hscript
fit01(rand($PT), 0, 9)

or
VEX
fit01(rand(@ptnum), 0, 9)

The values would not be 0-9. There would be 9 float values, each different.
Winter is coming!
User Avatar
Member
169 posts
Joined: April 2014
Offline
pusat
Depending on your seed you can do this using Python:

import random
random.seed(lvar('PT'))
return random.choice()

Excellent - Thank you!
Winter is coming!
User Avatar
Member
411 posts
Joined: June 2015
Offline
firefly9000
pusat
Depending on your seed you can do this using Python:

import random
random.seed(lvar('PT'))
return random.choice()

Excellent - Thank you!

How did you make sense of that? …would anyone please care to elaborate? I'm after the same thing here. Even simpler, trying to randomly pick among a short list of values (0, 90, 180, 270, 360) to create orientation randomness on some objects scattered using a copy node, but restricting them to those orientations only.

Cheers,

A.
User Avatar
Member
149 posts
Joined: Aug. 2014
Offline
Adriano
firefly9000
pusat
Depending on your seed you can do this using Python:

import random
random.seed(lvar('PT'))
return random.choice()

Excellent - Thank you!

How did you make sense of that? …would anyone please care to elaborate? I'm after the same thing here. Even simpler, trying to randomly pick among a short list of values (0, 90, 180, 270, 360) to create orientation randomness on some objects scattered using a copy node, but restricting them to those orientations only.

Cheers,

A.

I can't help you on the python part as I'm pretty rusty with python, but doing what you want in vex is fairly simple.

// create random integer from 0-3 generated from the point number, then multiply that by 90
float randVal = rand(@ptnum);
int degreeRotation = int(fit(randVal ,0,1,0,4)) * 90;

// @rot is a quaternion value a copy node will inherently read, you can also use other attributes like transform/orient/up etc…

float angle = radians(degreeRotation);
vector axis = {0,1,0};
@rot = quaternion(angle, axis);

hope that helps
Edited by electricalpencil - Feb. 15, 2018 15:37:19
User Avatar
Member
411 posts
Joined: June 2015
Offline
Thanks man, I wish it did help, but frankly it didn't. Just simple stuff like “int(fit(randVal ,0,1,0,4))” which i assume should return a value between 0 and 1 and be remapped between 0 and 4 and turn it into an integer…. just does not work for me in any context. Houdini gives me an error “unable to evaluate expression, bla di bla…”. So that's not a good start, is it.

Cheers,

A.
Edited by Adriano - March 1, 2018 13:14:21
User Avatar
Member
8043 posts
Joined: Sept. 2011
Offline
In vex it would be (int)float(floor(val*5))to get a value between 0 and 4 (assuming val already contained a random float between 0 and 1 from the rand() function.) You don't want to use fit/round because it won't be evenly distributed.

The hscript expression would be floor(rand(seed)*5), with seed being whatever you are keying the random with, e.g. ($PT, $F, etc)
Edited by jsmack - March 1, 2018 13:57:35
  • Quick Links