Search - User list
Full Version: How can i get a random numbers?
Root » Houdini Indie and Apprentice » How can i get a random numbers?
ordiza
random(a) is 0~1

but i want random numbers from input list.

for example
(0 1 2 3)->random->3
brianBurke
This is easy in vops. You can create a switch vop and plug your list of inputs (constants) into the switcher inputs. Then you can fit a normal random number to the number of inputs with the fit range vop. Then plug the result of the fit into your switcher.

Good luck dude!
ordiza
brianBurke
This is easy in vops. You can create a switch vop and plug your list of inputs (constants) into the switcher inputs. Then you can fit a normal random number to the number of inputs with the fit range vop. Then plug the result of the fit into your switcher.

Good luck dude!

thanks. but if i use fit node or expression in vopsop, it is make a float number.

i want integer random number within input integer number list.

if i use round(fit(random())), those are very same result.(like a 2,2,2,1,2…) that is not i want.
—-

input 0,1,2,3->random->0 or 1 or 2 or 3.
this is what i want.
Soothsayer
Try python.

import random
r = random.sample(,1)
return r
mawi
ordiza
brianBurke
This is easy in vops. You can create a switch vop and plug your list of inputs (constants) into the switcher inputs. Then you can fit a normal random number to the number of inputs with the fit range vop. Then plug the result of the fit into your switcher.

Good luck dude!

thanks. but if i use fit node or expression in vopsop, it is make a float number.

i want integer random number within input integer number list.

if i use round(fit(random())), those are very same result.(like a 2,2,2,1,2…) that is not i want.
—-

input 0,1,2,3->random->0 or 1 or 2 or 3.
this is what i want.

You are using the fit VOP to set number of samples.

Or use python…
ordiza
mawi
ordiza
brianBurke
This is easy in vops. You can create a switch vop and plug your list of inputs (constants) into the switcher inputs. Then you can fit a normal random number to the number of inputs with the fit range vop. Then plug the result of the fit into your switcher.

Good luck dude!

thanks. but if i use fit node or expression in vopsop, it is make a float number.

i want integer random number within input integer number list.

if i use round(fit(random())), those are very same result.(like a 2,2,2,1,2…) that is not i want.
—-

input 0,1,2,3->random->0 or 1 or 2 or 3.
this is what i want.

You are using the fit VOP to set number of samples.

Or use python…


Thank you for you guys help!
Soothsayer
Here is another technique only involving sops and expressions. Each frame it will randomly display a number out of a specified list. In this case the list is 0 12 5 6
Soothsayer
Here is another one with just 2 nodes. It takes a comma separated list and spits out a random item from it, changing every frame.

It includes one of the longest single expressions I have probably ever written.

`(substr(details(opinputpath(“.”,0),“s”),(ceil((fit01(rand($F),0,(strlen(details(opinputpath(“.”,0),“s”))))+1)/3)*3)-3,2)) :shock:

Edit: There is a little mistake. It returns a string wheras that should (probably) be a float, so here is the modified expression:


`atof((substr(details(opinputpath(“.”,0),“s”),(ceil((fit01(rand($F),0,(strlen(details(opinputpath(“.”,0),“s”))))+1)/3)*3)-3,2)))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB