How does one create an expression where the value would be randomly picked from a list of 9 pre-determined values.
Thank You!
Randomly picking from set value list
9317 8 2- firefly9000
- Member
- 169 posts
- Joined: April 2014
- Offline
- animatrix_
- Member
- 4731 posts
- Joined: Feb. 2012
- Offline
Depending on your seed you can do this using Python:
import random
random.seed(lvar('PT'))
return random.choice()
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
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
- PradeepBarua
- Member
- 443 posts
- Joined: Sept. 2012
- Offline
- firefly9000
- Member
- 169 posts
- Joined: April 2014
- Offline
- firefly9000
- Member
- 169 posts
- Joined: April 2014
- Offline
- Adriano
- Member
- 411 posts
- Joined: June 2015
- Online
firefly9000pusat
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.
- electricalpencil
- Member
- 149 posts
- Joined: Aug. 2014
- Offline
Adrianofirefly9000pusat
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
- Adriano
- Member
- 411 posts
- Joined: June 2015
- Online
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.
Cheers,
A.
Edited by Adriano - March 1, 2018 13:14:21
- jsmack
- Member
- 8045 posts
- Joined: Sept. 2011
- Offline
In vex it would be
The hscript expression 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